officel
2/12/2019 - 9:50 AM

[terraform] map の list の中から特定の要素を抽出するやつ

[terraform] map の list の中から特定の要素を抽出するやつ

$ cat test.tf
variable "employee" {
  type = "list"

  default = [
    {
      no = 1

      name = "田中"
    },
    {
      no = 2

      name = "佐藤"
    },
  ]
}

data "null_data_source" "get_employee" {
  count = "${length(var.employee)}"

  inputs = {
    name = "${lookup(var.employee.[count.index] , "name")}"
  }
}

output "names" {
  value = ["${data.null_data_source.get_employee.*.outputs.name}"]
}


$ terraform output
names = [
    田中,
    佐藤
]