我正在尝试构建这个扁平结构:
locals {
containers = flatten([
for storage_key, st in var.Storage : [
for cont_key, cont in st.containers : {
storage_key = storage_key,
storage_name = st.name,
cont_name = cont_key,
access_type = cont.container_access_type
}
]
])
}
但我的问题是变量规格允许容器映射为空:
variable "Storage" {
type = map(object({
name = string
containers = optional(map(object({
container_access_type = string
})))
}))
}
with these default values:
Storage = {
stor1 = {
name = "accntpriv"
containers = {
mgmt-media = {
container_access_type = "private"
}
mgmt-comm = {
container_access_type = "private"
}
mgmt-static = {
container_access_type = "blob"
}
}
}
}
我想将容器添加到由存储名称标识的现有存储帐户。
感谢您的帮助! 沃尔夫冈
这有效,感谢您的耐心
locals {
containers = flatten([
for storage_key, st in var.Storage : [
for cont_key, cont in coalesce(st.containers, {}) :
{
storage_key = storage_key,
storage_name = st.name,
cont_name = cont_key,
access_type = cont.container_access_type
}
]
])
}