So, I have a variable that contains a list of strings that map to subdomains. These produce outputs of their ns servers in remote state. Now, what I’m trying to do is do a terraform apply on the root account to create ns records so that the subdomains work.
My variable is setup like this:
sub_domains = [
“dev”,
“test”
]
While my resource block is setup like this:
resource "aws_route53_record" "subns" {
for_each = toset(var.sub_domains)
zone_id = aws_route53_zone.root[0].zone_id
name = "${each.key}.domain.io"
type = "NS"
ttl = "300"
records = data.terraform_remote_state.[each.key].outputs.hosted_zone_name_servers
}
Currently, I’m getting this error:
Error: Invalid attribute name
on main.tf line 24, in resource “aws_route53_record” “subns”:
24: records = data.terraform_remote_state.[each.key].outputs.hosted_zone_name_servers
An attribute name is required after a dot.
How can I get this to work?
Thanks!