【问题标题】: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