I am trying to create multiple alias DNS records in terraform using for_each. I am getting an error when specifying the name and zone ID of the Alias name. My question is how do I read from a variable defined as a set of strings? Below is my code block and variables defined:
resource "aws_route53_record" "alias_records" {
for_each = var.alias_names
zone_id = aws_route53_zone.zone.zone_id
name = each.key
type = "A"
alias {
name = var.alias_dns_names[each.key]
zone_id = var.alias_zone_ids[each.key]
evaluate_target_health = false
}
}
variable "alias_names" {
type = set(string)
}
variable "alias_dns_names" {
type = set(string)
}
variable "alias_zone_ids" {
type = set(string)
}
Error: Invalid index
on alias.tf line 8, in resource "aws_route53_record" "alias_records":
8: name = var.alias_dns_names[each.key]
This value does not have any indices.
Error: Invalid index
on alias.tf line 9, in resource "aws_route53_record" "alias_records":
9: zone_id = var.alias_zone_ids[each.key]
This value does not have any indices.
alias_names = [
"alias1",
"alias2",
"alias3"
}
alias_dns_names = [
"alias_dns_1",
"alias_dns_2",
"alias_dns_3"
}
alias_zone_ids = [
"alias_zone_1",
"alias_zone_2",
"alias_zone_3"
}
Mapinstead. - Matt Schuchard