在Terraform脚本中使用的ARM Return App Service环境ID [英] ARM Return App Service Environment ID to use in Terraform Script

查看:96
本文介绍了在Terraform脚本中使用的ARM Return App Service环境ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Terraform不允许部署App Service环境,因此我正在使用azurerm_template_deployment作为解决方法.但是,我想在以后创建的App Service Plan资源中引用App Service Environment ID.如何使用这种方法获取并保存App Service环境的ID?

Terraform does not allow for the deployment of App Service Environments so I am using the azurerm_template_deployment as a work around. However, I want to reference the App Service Environment ID in an App Service Plan resource that I am creating later. How would I get and save the ID of the App Service Environment using this method?

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

I am using the depends_on tag in the app service plan resource to ensure its creation after the app service environment, but I can not figure out how to get the id out of the creation and save to a variable. I think that it would involve the use of the variable and output tags of the ARM template.

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模板中,使用

In the ARM template, use outputs to set an output to the app service environment ID.

(这样的事情,没有机会进行测试,对更改的任何反馈将不胜感激!)

(something like this, didn't have a chance to test, any feedback on changes would be greatly appreciated!)

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

azurerm_template_deployment支持 outputs地图.使用此地图,您可以然后设置

The azurerm_template_deployment supports an outputs map. Using this map, you can then set

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的输出)

The depends_on shouldn't be necessary and should be implicit (since the azurerm_app_service_plan uses an output of azurerm_template_deployment)

这篇关于在Terraform脚本中使用的ARM Return App Service环境ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆