やりたいこと
ループしているリソースをOutputで出力するときには、Outputもループさせて出力するのがいいと思う。
以下の場合は、Map型のリソースなので、Mapで出力してあげるほうがたぶんいい。
一応使い分けるられるように2パターン書いてます。
サンプル
locals {
files = [
{
content = "aaa"
name = "hello1"
},
{
content = "bbb"
name = "hello2"
},
{
content = "ccc"
name = "hello3"
},
]
}
resource "local_file" "hello" {
for_each = { for i in local.files : i.name => i }
content = each.value.content
filename = each.value.name
}
## list型で出力する例
output "list" {
value = values(local_file.hello).*.content
}
## map型で出力する例
output "map" {
value = {
for k, v in local_file.hello : k => v.content
}
}
出力
Outputs:
list = [
"aaa",
"bbb",
"ccc",
]
map = {
"hello1" = "aaa"
"hello2" = "bbb"
"hello3" = "ccc"
}