【问题标题】:Terraform: error when adding Diagnostic setting to Azure App ServiceTerraform:将诊断设置添加到 Azure 应用服务时出错
【发布时间】:2021-02-23 00:11:48
【问题描述】:

请参阅下面我用来添加诊断设置以将应用服务日志发送到日志分析工作区的配置。

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting

    resource "azurerm_app_service" "webapp" {
      for_each = local.apsvc_map_with_locations
    
      name                = "${var.regional_web_rg[each.value.location].name}-${each.value.apsvc_name}-apsvc"
      location            = each.value.location
      resource_group_name = var.regional_web_rg[each.value.location].name
      app_service_plan_id = azurerm_app_service_plan.asp[each.value.location].id
      https_only          = true
           
      identity {
        type         = "UserAssigned"
        identity_ids = each.value.identity_ids
      }
    }
    
    resource "azurerm_monitor_diagnostic_setting" "example" {
      for_each = local.apsvc_map_with_locations
    
      name                       = "example"
      target_resource_id         = "azurerm_app_service.webapp[${each.value.location}-${each.value.apsvc_name}].id"
      log_analytics_workspace_id = data.terraform_remote_state.pod_bootstrap.outputs.pod_log_analytics_workspace.id
      log {
        category = "AuditEvent"
        enabled  = false
    
        retention_policy {
          enabled = false
        }
      }
    
      metric {
        category = "AllMetrics"
    
        retention_policy {
          enabled = false
        }
      }
    }

错误

Can not parse "target_resource_id" as a resource id: Cannot parse Azure ID: parse "azurerm_app_service.webapp[].id": invalid URI for request
2020-11-06T20:19:59.3344089Z 
2020-11-06T20:19:59.3346016Z   on .terraform\modules\web.web\pipeline\app\apsvc\app_hosting.tf line 127, in resource "azurerm_monitor_diagnostic_setting" "example":
2020-11-06T20:19:59.3346956Z  127: resource "azurerm_monitor_diagnostic_setting" "example" {
2020-11-06T20:19:59.3347091Z 

【问题讨论】:

    标签: terraform


    【解决方案1】:

    您可以尝试以下方法:

    target_resource_id         = azurerm_app_service.webapp["${each.value.location}-${each.value.apsvc_name}"].id
    

    代替:

    target_resource_id         = "azurerm_app_service.webapp[${each.value.location}-${each.value.apsvc_name}].id"
    

    【讨论】:

      猜你喜欢
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 2019-11-28
      • 2022-11-13
      相关资源
      最近更新 更多