Last active
November 17, 2022 03:02
-
-
Save officel/c077f27852a01822b82e72e724b01327 to your computer and use it in GitHub Desktop.
[terraform] map の list の中から特定の要素を抽出するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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