如何将地图值与terraform结合起来?

时间:2018-05-28 04:34:37

标签: terraform

我试过这个:

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()仅允许平面地图。有解决方法吗?

1 个答案:

答案 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
]