簡體   English   中英

需要在 terraform 中包含值或者使用多個循環來存儲變量

[英]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會更容易,從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"]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM