Hello,
I have an issue where Terraform (1.7.5) always wants to add or remove all route53 zone vpc associations.
My module creates a r53 zone for each item in a list and then associates each zone with each vpc given as a list. I use a local resource to create
a map of the associations.
Any pointers on how to stop the resources recreating? Im guessing its to do with ordering in the for_each in the association resource but I’m not sure how to fix it.
locals {
associations = merge([for item in var.vpc_ids_to_associate_with_phz : {
for k, v in aws_route53_zone.private_hosted_zone : "${k}/${item}" => {
zone_id = v.zone_id
vpc_id = item
}
}
]...)
}
variable "vpc_endpoints" {
description = "A list of services to create endpoints for"
type = list(string)
default = []
}
variable "vpc_ids_to_associate_with_phz" {
type = list(string)
description = "List of VPC IDs to associate with the private hosted Route 53 zone"
default = []
}
resource "aws_route53_zone" "private_hosted_zone" {
for_each = toset(var.vpc_endpoints)
name = "${each.key}.${data.aws_region.current.name}.amazonaws.com"
vpc {
vpc_id = aws_vpc.main_vpc.id
}
tags = {
Name = "${each.key}-phz"
env = "${var.environment_tag}"
}
}
resource "aws_route53_zone_association" "phz_association" {
for_each = local.associations
zone_id = each.value.zone_id
vpc_id = each.value.vpc_id
}