在使用for_each循环遍历嵌套的map时,可以通过使用嵌套的for_each循环来访问变量。例如:
locals {
my_map = {
"key1" = {
"value1" = "foo"
"value2" = "bar"
}
"key2" = {
"value1" = "baz"
"value2" = "qux"
}
}
}
resource "null_resource" "example" {
for_each = local.my_map
provisioner "local-exec" {
command = "echo ${each.value.value1} ${each.value.value2}"
}
}
在上面的例子中,我们遍历了名为my_map的本地变量,并通过嵌套的for_each循环访问了嵌套的map中的value1和value2变量。