gpt4 book ai didi

azure - ARM 返回要在 Terraform 脚本中使用的应用服务环境 ID

转载 作者:行者123 更新时间:2023-12-03 02:50:37 26 4
gpt4 key购买 nike

Terraform 不允许部署应用服务环境,因此我使用 azurerm_template_deployment 作为解决方法。但是,我想在稍后创建的应用服务计划资源中引用应用服务环境 ID。如何使用此方法获取并保存应用服务环境的 ID?

我在应用程序服务计划资源中使用depends_on标记来确保其在应用程序服务环境之后创建,但我不知道如何从创建中获取id并将其保存到变量中。我认为这会涉及到ARM模板的变量和输出标签的使用。

resource "azurerm_template_deployment" "ase" {
name = "ILBASE_ARM_template"
resource_group_name = "${azurerm_resource_group.ase.name}"

template_body = <<DEPLOY

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ilbase_name": {
"type": "string"
},
"ilbase_domain_name": {
"type": "string"
},
"ilbase_subnet_name": {
"type": "string"
},
"ilbase_rglocation": {
"defaultValue": "East US",
"type": "string"
},
"vnet_id": {
"type": "string"
}
},
"variables": {
},
"resources": [
{
"apiVersion": "2016-09-01",
"type": "Microsoft.Web/hostingEnvironments",
"name": "[parameters('ilbase_name')]",
"kind": "ASEV2",
"location": "[parameters('ilbase_rglocation')]",
"properties": {
"name": "[parameters('ilbase_name')]",
"location": "[parameters('ilbase_rglocation')]",
"virtualNetwork": {
"Id": "[parameters('vnet_id')]",
"Subnet": "[parameters('ilbase_subnet_name')]"
},
"internalLoadBalancingMode": "Web, Publishing",
"multiSize": "Standard_D1_V2",
"multiRoleCount": 2,
"workerPools": null,
"ipsslAddressCount": 0,
"dnsSuffix": "[parameters('ilbase_domain_name')]",
"networkAccessControlList": [],
"frontEndScaleFactor": 15,
"apiManagementAccountId": null,
"suspended": false,
"dynamicCacheEnabled": null,
"clusterSettings": null
}
}
],
"outputs": {
}
}

DEPLOY

parameters {
"vnet_id" = "${azurerm_virtual_network.main_vnet.id}"
"ilbase_subnet_name" = "${azurerm_subnet.ase.name}"
"ilbase_name" = "${var.env}-ASE-001"
"ilbase_domain_name" = "${var.dnsName}"
"ilbase_rglocation" = "${var.location}"
}

deployment_mode = "Incremental"
}

resource "azurerm_app_service_plan" "test" {
name = "api-appserviceplan-pro"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.ase.name}"
app_service_environment_id = ????????????????????

sku {
tier = "Isolated"
size = "S1"
}

depends_on = ["azurerm_template_deployment.ase"]
}

预先感谢您的帮助!

最佳答案

在 ARM 模板中,使用 outputs将输出设置为应用服务环境 ID。

(像这样的东西,没有机会测试,任何有关更改的反馈将不胜感激!)

"outputs": {
"app_service_evironment_id": {
"type": "string",
"value": "[resourceId('Microsoft.Web/hostingEnvironments', parameters('ilbase_name'))]"
}
}

azurerm_template_deployment 支持outputs map 。使用此 map ,您可以设置

azurerm_app_service_plan.test.app_service_environment_id = azurerm_template_deployment.ase.outputs["app_service_evironment_id"]

depends_on 不应该是必需的,并且应该是隐式的(因为 azurerm_app_service_plan 使用 azurerm_template_deployment 的输出)

关于azure - ARM 返回要在 Terraform 脚本中使用的应用服务环境 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56278126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com