Hi!
I have multiple VPCs in different regions with the same configuration of hard-/software (I call it "clusters"). For each VPC I want to create a Route 53 hosted zone, connected to this VPC with local domain example.local. Each instance within the VPC gets its own domain name like:
- foo.example.local
- bar.example.local
- etc.
This is needed to configure my software in private networks, just to get rid of IPs in configs. So I know that an instance with role 'foo' is always at foo.example.local in each VPC I maintain. And this all works brilliant with Terraform.
The problem is that when I try to maintain different VPCs with one Terraform config it is impossible to create second hosted zone with the same local domain. Teffaform plan says it will destroy my current hosted zone and create a new one. How can I maintain multiple hosted zones with the same domain? AWS itself allows me to create multiple zones with same domain manually and link to to another VPC, so I believe the issue is somewhere in Terraform.
Here's my simplified Terraform config:
variable "access_key" { }
variable "secret_key" { }
variable "cluster_name" { }
variable "region" { }
variable "key_name" { }
provider "aws" { access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
resource "aws_vpc" "main" {
enable_dns_hostnames = true
}
resource "aws_instance" "foo" {
ami = "${lookup(var.app_amis, var.region)}"
instance_type = "t2.micro"
key_name = "..."
subnet_id = "..."
vpc_security_group_ids = ["..."]
}
...
resource "aws_route53_zone" "local" {
name = "example.local"
}
resource "aws_route53_record" "foo" {
zone_id = "${aws_route53_zone.local.zone_id}"
type = "A"
ttl = "300"
records = ["${aws_instance.foo.private_ip}"]
}
So when I use another cluster_name and region everything is OK except the last two Route 53 resources - they get destroyed and created again in new region...
Thanks!