当我有一个托管区域时,我可以轻松创建该区域,然后通过按名称引用托管区域,在委托账户中为该区域创建 NS 记录。
- 编辑为了避免混淆,这是我想要实现的目标,但对于多个托管区域并且域的所有者是管理帐户:https://dev.to/arswaw/create-a-subdomain-in-amazon-route53-in-2-minutes-3hf0 https://dev.to/arswaw/create-a-subdomain-in-amazon-route53-in-2-minutes-3hf0
现在我需要创建多个托管区域并将名称服务器记录传递回父帐户,我不确定是否可以(或者如何)引用多个资源。阅读本文可能没有多大意义,因此下面的代码是我所掌握的。
我现在有一个for_each
循环将循环遍历字符串列表并为每个字符串创建一个托管区域,然后我想在另一个帐户中创建相应的 NS 记录,请注意,我正在使用单独的提供程序provider = aws.management_account
连接到管理帐户,这对于单个托管区域来说效果很好。
我不知道如何引用托管区域,是否有一些语法或者我的方法错误?
resource "aws_route53_zone" "public_hosted_zone" {
for_each = local.aws_zones
name = "${each.value}.${var.domain}"
}
resource "aws_route53_record" "ns_records" {
for_each = local.aws_zones
provider = aws.management_account
allow_overwrite = true
name = "${each.value}.${var.domain}"
ttl = 30
type = "NS"
zone_id = data.aws_ssm_parameter.public_hosted_zone_id.value
records = [
aws_route53_zone.public_hosted_zone.name_servers[0], # Here is my old code which works for a single hosted zone but I cannot work out how to reference multiples created above
aws_route53_zone.public_hosted_zone.name_servers[1],
aws_route53_zone.public_hosted_zone.name_servers[2],
aws_route53_zone.public_hosted_zone.name_servers[3]
]
}
自从你的local.aws_zones
设置为 ["dev", "test", "qa"],你的aws_route53_zone.public_hosted_zone
将是一个带有键“dev”、“test”、“qa”的地图。
因此,要在您的aws_route53_record
, 你可以试试:
resource "aws_route53_record" "ns_records" {
for_each = local.aws_zones
# other attributes
records = aws_route53_zone.public_hosted_zone[each.key].name_servers
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)