To associate a Route53 zone with a VPC in a different AWS account, you must handle two distinct steps:
- Authorization (Inside Module): The account owning the zone must authorize the VPC association. This is handled within the module using the
vpc_association_authorizations argument. - Association (Outside Module): The account owning the VPC must perform the actual association using the
aws_route53_zone_association resource. This resource is not included in the module.
Managing the ignore_vpc variable
To avoid disruptive diffs when managing associations, use the ignore_vpc variable. Note that changing this value requires a state move because Terraform cannot use variables in lifecycle blocks.
Moving from ignore_vpc = false to true:
terraform state mv 'module.zone.aws_route53_zone.this[0]' 'module.zone.aws_route53_zone.ignore_vpc[0]'
Moving from ignore_vpc = true to false:
terraform state mv 'module.zone.aws_route53_zone.ignore_vpc[0]' 'module.zone.aws_route53_zone.this[0]'
Alternatively, use a moved block in your HCL configuration.
module "zone" {
source = "terraform-aws-modules/route53/aws"
name = "terraform-aws-modules-example.com"
comment = "Private zone for terraform-aws-modules example"
# Ignore VPC after creation to avoid disruptive diff with associations
ignore_vpc = true
vpc = {
default = {
vpc_id = "vpc-1234556abcdef"
vpc_region = "eu-west-1"
}
}
vpc_association_authorizations = {
external = {
vpc_id = "vpc-987564fedcba"
vpc_region = "eu-west-1"
}
external_region = {
vpc_id = "vpc-1a2b3c4d56e7f8"
vpc_region = "us-east-1"
}
}
tags = {
Environment = "example"
Project = "terraform-aws-route53"
}
}