【发布时间】:2021-08-19 10:34:08
【问题描述】:
无法使用 C# 程序访问 azure cloud shell
请帮助我,我无法访问 azure cloud shell,我在 azure cloud shell 中设置了一个脚本,但现在我无法使用 C# 代码打开 azure cloud shell。我想要一个蔚蓝的云壳
预期结果
invoke access azure cloud shell ==> run terraform script ==> show output
C# 代码
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
};
这是我在本地和云端运行的 terraform 脚本
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
【问题讨论】:
-
为什么要通过 Azure Cloud Shell 中的 C# 应用程序运行 terrafrom?
-
我想通过我的应用程序访问 azure 并使用 terraform 创建一个单独的数据库,我知道我们可以使用浏览器直接打开一个 azure cloud shell。
-
是的,我从代码中理解了你的地形。我的问题是关于您对运行 terraform 的偏好。为什么不使用 Azure Devops 中的管道并将状态文件放入存储帐户。
-
因为我的客户需要。
标签: c# azure-devops terraform terraform-provider-azure azure-cloud-shell