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 service_url = "https://${(xxxx))}.com 中有 ${val[0]},即https://dev.com,https://qa.com
uj5u.com熱心網友回復:
我認為在您的情況下,重新組織, for_eachfrom listto會更容易map:
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"]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/431829.html
