Skip to content

Instantly share code, notes, and snippets.

@officel
Last active November 17, 2022 03:02
Show Gist options
  • Save officel/c077f27852a01822b82e72e724b01327 to your computer and use it in GitHub Desktop.
Save officel/c077f27852a01822b82e72e724b01327 to your computer and use it in GitHub Desktop.
[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 = [
田中,
佐藤
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment