0

Unable to access azure cloud shell using C# program

please help me I am unable to access the azure cloud shell, I set up a script in the azure cloud shell but now I can't open the azure cloud shell using C# code. I want an azure cloud shell

expected result invoke access azure cloud shell ==> run terraform script ==> show output

C# code


string extendCommand = "terraform init ";
ProcessStartInfo procStartInfo = new ProcessStartInfo("https://shell.azure.com/powershell", "/terraform_test" + extendCommand) //terraform_test folder name
            {
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true
            };

            Process proc = new Process
            {
                StartInfo = procStartInfo
            };

Here is my running terraform script local and cloud shell

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=2.46.0"
    }
  }
}

#provider "azurerm" {
# version = "~> 1.34.0"
#}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}

# Hub RG
resource "azurerm_resource_group" "rg" {
  name     = "resource-name-01"
  location = "eastus"
}

####################### Database setup ################################
resource "azurerm_storage_account" "st" {
  name                     = "irs01st"
  resource_group_name      = azurerm_resource_group.rg.name
  location                 = azurerm_resource_group.rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

#resource "azurerm_sql_server" "ss" {
#  name                         = "irs01-ss"
#  resource_group_name          = azurerm_resource_group.rg.name
#  location                     = azurerm_resource_group.rg.location
#  version                      = "12.0"
#  administrator_login          = "admin"
#  administrator_login_password = "Abc@123"
#}

####################### Start Sql server #############################
resource "azurerm_mssql_database" "sqldb" {
  name      = "db01"
  server_id = azurerm_sql_server.ss.id
  #  resource_group_name = azurerm_resource_group.rg.name
  #  storage_account_name  = azurerm_storage_account.st.name
  collation    = "SQL_Latin1_General_CP1_CI_AS"
  license_type = "LicenseIncluded"
  max_size_gb  = 1
  #read_scale   = true
  sku_name     = "Basic"
  #zone_redundant = true #this is required sku > basic
}

################################# OR ##################################
resource "azurerm_sql_database" "sqldb" {
  name                             = "sql-db"
  resource_group_name              = "${azurerm_resource_group.rg.name}"
  location                         = "${azurerm_resource_group.rg.location}"
  server_name                      = "${azurerm_sql_server.ss.name}"
  edition                          = "Basic"
  collation                        = "SQL_Latin1_General_CP1_CI_AS"
  create_mode                      = "Default"
  requested_service_objective_name = "Basic"
}

########################## End sql server ############################```
 
Thanks in advance

1 Answers1

0

You can't. The cloud shell is not designed to be used from scripting. You would need to write complicated browser automation to drive the UI, if it were possible at all. This is not a reasonable requirement and you need to rethink your proposed solution.

Do you mean using the Azure CLI? If so, please edit the question to clarify this. The cloud shell is one of several environments for the CLI, but the CLI is not the cloud shell.

Tom W
  • 5,108
  • 4
  • 30
  • 52