0

我有以下数据结构,并且我有一个需要循环遍历此地图的模块:

   webapps = {
w1= {
    site_config = {}
    slots = {
      dev = {
        site_config = {}
      },
      uat-staging = {
        site_config = {
          site_config = {}
        }
      },
      uat-live = {
        site_config = {
          site_config = {}
        }
      },
      production-stage = {
        site_config = {
          site_config = {}
        }
      }
    }
    core_app_service_to_blob_role_assignment = {
      app   = ["container1", "container2"]
      audit = ["container3", "container4"]
    }

  }
      
      }

我用 for_each 和 for 循环调用模块,它应该生成一个新的地图,其中 key = webapp name (w1) 和 value = core_app_service_to_blob_role_assignment :

module "role-assignment" {
  providers = {
    azurerm         = azurerm
    azurerm.central = azurerm.central
  }

  for_each = {for k, v in var.webapps : k => { for sa, container in v.core_app_service_to_blob_role_assignment : sa => container }}

  source = "./modules/role-assignment"

  assignments = each.value["app"]
  principle_id = module.app-service-core[each.key].app_service_slot_identity_service_principal_id
}

但得到以下错误:

│ Error: Invalid index
│
│   on main.tf line 102, in module "role-assignment":
│  102:   assignments = each.value["app"]
│     ├────────────────
│     │ each.value is object with no attributes
│
│ The given key does not identify an element in this collection value.
4

0 回答 0