如何在 Terraform 中转换嵌套数组
How to turn a nested array in Terraform
如何使用地图检索嵌套数组?
我想将要注册的记录从本地传递到Route53。
例子
locals {
cname = {
"bbb.example.io" = {
records = ["example"]
}
"aaa.example.io" = {
records = [
"example1",
"example2",
"example3"
]
}
}
}
resource "aws_route53_record" "cname" {
for_each = local.cname
name = each.key
records = [] ←Problem areas
ttl = 300
type = "CNAME"
zone_id = aws_route53_zone.example.zone_id
}
鉴于您在此示例中设置 for_each
的方式,该块中的 each.value
将是 local.cname
地图中的相应对象,因此您可以访问records
该对象的通常方式的属性:
resource "aws_route53_record" "cname" {
for_each = local.cname
name = each.key
records = each.value.records
ttl = 300
type = "CNAME"
zone_id = aws_route53_zone.example.zone_id
}
如何使用地图检索嵌套数组? 我想将要注册的记录从本地传递到Route53。
例子
locals {
cname = {
"bbb.example.io" = {
records = ["example"]
}
"aaa.example.io" = {
records = [
"example1",
"example2",
"example3"
]
}
}
}
resource "aws_route53_record" "cname" {
for_each = local.cname
name = each.key
records = [] ←Problem areas
ttl = 300
type = "CNAME"
zone_id = aws_route53_zone.example.zone_id
}
鉴于您在此示例中设置 for_each
的方式,该块中的 each.value
将是 local.cname
地图中的相应对象,因此您可以访问records
该对象的通常方式的属性:
resource "aws_route53_record" "cname" {
for_each = local.cname
name = each.key
records = each.value.records
ttl = 300
type = "CNAME"
zone_id = aws_route53_zone.example.zone_id
}