我试过这个:
variable "records" {
type = "map"
default = {
"mediapop.co." = ["www.mediapop.co"],
"mediapopinc.com." = ["mediapopinc.com", "www.mediapopinc.com"] ,
"mediapop.sg." = ["mediapop.sg", "www.mediapop.sg"],
}
}
output "records" {
value = "${flatten(values(var.records))}"
}
但values()
仅允许平面地图。有解决方法吗?
答案 0 :(得分:3)
使用transpose:
output "transpose" {
value = "${transpose(var.records))"
}
output "values" {
value = "${keys(transpose(var.records)))"
}
输出
transpose = {
mediapop.sg = [mediapop.sg.]
mediapopinc.com = [mediapopinc.com.]
www.mediapop.co = [mediapop.co.]
www.mediapop.sg = [mediapop.sg.]
www.mediapopinc.com = [mediapopinc.com.]
}
values = [
mediapop.sg,
mediapopinc.com,
www.mediapop.co,
www.mediapop.sg,
www.mediapopinc.com
]