gpt4 book ai didi

azure - 需要在 terraform 中包含值或使​​用多个循环来存储变量

转载 作者:行者123 更新时间:2023-12-03 02:15:42 28 4
gpt4 key购买 nike

env = ["dev", "qa"]

services = ["net", "go", "two", "three", "four", "five"]

resource "azurerm_api_management_api" "api" {
for_each = toset([for val in setproduct(var.env, var.services): "${val[0]}-${val[1]}"])
name = "${each.key}"
resource_group_name = azurerm_resource_group.xx.name
api_management_name = azurerm_api_management.xxx.name
revision = "1"
path = "${each.key}"
display_name = "${each.key}"
service_url = "https://${(xxxx))}.com"
protocols = ["https"]
}

我想在 service_url 中添加 ${val[0]} service_url = "https://${(xxxx))}.com",即 https://dev.com , https://qa.com

最佳答案

我认为在你的情况下,重新组织 for_each 会更容易,从 listmap:

resource "azurerm_api_management_api" "api" {
for_each = {for val in setproduct(var.env, var.services): "${val[0]}-${val[1]}" => {env = val[0], service = val[1]} }
name = "${each.key}"
resource_group_name = azurerm_resource_group.xx.name
api_management_name = azurerm_api_management.xxx.name
revision = "1"
path = "${each.key}"
display_name = "${each.key}"
service_url = "https://${each.value.env}.com"
protocols = ["https"]
}

关于azure - 需要在 terraform 中包含值或使​​用多个循环来存储变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71231705/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com