尝试在Terraform中使用formatlist函数以产生输出。 我正在寻找类似这样的输出
example.com: [ns1.aws.com,
ns2.aws.com,
ns3.aws.com]
我已经输出了类似这样的框架
output "example_name_servers" {
value = "${
formatlist(
"{\"%v\": \"%v\"}",
aws_route53_zone.example.*.name,
aws_route53_zone.example.*.name_servers,
)
}"
}
显然,它会引发错误
formatlist: list has a non-string element (string) in:
但是aws_route53_zone.main.*.name_servers
是一个列表。
答案 0 :(得分:0)
我在formatlist中将元素加入了字符串
output "example_name_servers" {
value = "${
formatlist(
"{\"%v\": \"%v\"}",
aws_route53_zone.example.*.name,
join(", ", aws_route53_zone.example.*.name_servers),
)
}"
}