我有这个变种:
variable "my_var" {
type = map(object({
param = list(string)
}))
default = {
aaa = {
param = [
"sldkjflksdf",
]
}
bbb = {
param = [
"oejkfoekfoe",
"wewewwe",
"sssssss"
]
}
ccc = {
param = [
"qqqqqqqqqqqqq",
"llllllllllll",
"huhuhuh"
]
}
}
}
我想在资源中使用for_each来遍历此映射中的所有“参数”。因此,我想合并嵌套映射的所有参数数组,然后使用foreach对其进行循环。我尝试使用拼合,但不确定如何工作。我需要在本地变量中创建一个新变量吗?
答案 0 :(得分:0)
最好将其放在这样的局部变量中
locals {
all_params = flatten([for v in values(var.my_var) : v["param"]])
}
那你就可以写
resource "your_resource" "example" {
for_each = local.all_params
# ... access elements with ${each.value} ...
}