[英]how to use Loops in Terraform to deploy 2 different azure resources
[英]need to include value in terraform or use multiple loops to store variable
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"]
}
我想要 ${val[0]} inside service_url service_url = "https://${(xxxx))}.com",即https: //dev.com,https://qa.com
我認為在你的情況下,重新組織for_each
會更容易,從list
到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"]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.