azure - Terraform:错误:解析应用服务资源 ID 时出错

标签 azure terraform terraform-provider-azure terraform0.12+

这是 this question 的延续

resource "azurerm_app_service_slot" "app_service_slot_template"   {
  for_each = {for sl in "${var.app_service_slots}" : sl.name => sl }
  
  app_service_name = "${var.mandatory_prefix}-${var.app_service_name}"
  resource_group_name = "${var.resource_group_name}"
  app_service_plan_id = "${data.azurerm_app_service_plan.service_plan.id}"
  location = "${var.resource_location}"
  https_only = true

 
      
        
  name =  "${each.value["name"]}"
  
  dynamic "site_config" {
    for_each = "${var.site_config}"
    content {
      min_tls_version = lookup(site_config.value, "min_tls_version", null)
      python_version = lookup(site_config.value, "python_version", null)
      java_version = lookup(site_config.value, "java_version", null)
      always_on = lookup(site_config.value, "always_on", null)
      app_command_line = lookup(site_config.value, "app_command_line", null)
      dotnet_framework_version = lookup(site_config.value, "dotnet_framework_version", null)          
    }
  }
  
  dynamic "connection_string" {
    for_each =  "${each.value["connection_strings"]}"
    content {
      name = "${connection_string.value["name"]}"
      type = "${connection_string.value["type"]}"
      value = "${connection_string.value["value"]}"
    }
  }

  app_settings = "${merge(each.value["app_settings"], local.additional_app_settings)}"
}



  # Get the Id of the subnet
data "azurerm_subnet" "azurerm_subnet_template" {
  name                 = "${var.subnet_name}"
  virtual_network_name = "${var.virtual_network_name}"
  resource_group_name  = "${var.vnet_resource_group_name}"
}

resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot" {
  for_each = {for sl in "${azurerm_app_service_slot.app_service_slot_template}" : sl.name => sl }

  app_service_id = "${each.value.id}"
  subnet_id      = "${data.azurerm_subnet.azurerm_subnet_template.id}"
  depends_on = [azurerm_app_service_slot.app_service_slot_template]
}

这在 Terraform 计划上完美运行,但是在应用过程中失败并出现以下错误

Error: Error parsing App Service Resource ID

on .terraform/modules/generic_app_service/main.tf line 235, in resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot": 235: resource "azurerm_app_service_virtual_network_swift_connection" "azureapp_vnet_integration_for_slot" {

我可以从计划输出中确认 app_service_id 正在获取/传递 azure 插槽的正确资源 ID,但不知道为什么它提示应用服务资源 ID

最佳答案

app_service_id 的文档写:

The ID of the App Service or Function App to associate to the VNet. Changing this forces a new resource to be created.

因此它应该是 azurerm_app_serviceazurerm_function_app 的 ID。但您正在尝试使用 azurerm_app_service_slot,这是一种不同的资源。

关于azure - Terraform:错误:解析应用服务资源 ID 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67985330/

相关文章:

azure - 在 terraform 中,使字符串变量在操作 block 中可选

azure - 用于调整单个分片大小的 SQL 命令 Windows SQL Azure

azure - Azure OCR 是否支持阿拉伯语和印地语?

c# - Azure WebJobs 3.0 上的 IQueueProcessorFactory?

Terraform,资源可以作为变量传递到模块中吗?

amazon-web-services - 如何在 Terraform 中使用 AWS account_id 变量

google-cloud-platform - 使用 terraform 配置 bigquery 数据集

azure - 如何使用 Azure Devops 将 powershell 列表变量传输到 terraform?

terraform - 如何在 Hashicorp Terraform 中配置环境变量

c# - CosmosDB SQL API : Change property Name - (Partial Updates .Net SDK 或循环)