如何使用map检索嵌套数组?我想把要注册的记录从本地传递到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
}