【问题标题】:how to get output when using for_each in terraform for azure在 terraform for azure 中使用 for_each 时如何获取输出
【发布时间】:2023-02-25 16:10:06
【问题描述】:
resource "azurerm_windows_web_app_slot" "staging-1" {
  for_each=toset(["staging-one","staging-two"])
  name=each.value
  app_service_id=azurerm_windows_web_app.app82377789945.id
  site_config {
    application_stack{
      current_stack="dotnet"
      dotnet_version="v6.0"
    }
  }  
}

在输出中我想获得两个插槽 ID。

【问题讨论】:

    标签: azure terraform azure-web-app-service terraform-provider-azure


    【解决方案1】:

    在这种情况下,您可以使用内置的 values 函数 [1]。返回结果将是一个值列表:

    resource "azurerm_windows_web_app_slot" "staging-1" {
      for_each=toset(["staging-one","staging-two"])
      name=each.value
      app_service_id=azurerm_windows_web_app.app82377789945.id
      site_config {
        application_stack{
          current_stack="dotnet"
          dotnet_version="v6.0"
        }
      }  
    }
    
    output "slot_ids" {
      value = values(azurerm_windows_web_app_slot.staging-1)[*].id
    }
    

    [1] https://developer.hashicorp.com/terraform/language/functions/values

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 2022-01-11
      • 2020-06-28
      • 1970-01-01
      • 2021-03-07
      • 2021-05-25
      • 2021-09-08
      • 2020-08-04
      • 1970-01-01
      相关资源
      最近更新 更多