Hello all,
I'm running into trouble using an aws_route53_record in the following terraform plan:
resource "aws_instance" "app" {
associate_public_ip_address = false
tags {
Name = "${var.my_instance_name}”
}
}
resource "aws_eip" "app" {
instance = "${aws_instance.app.id}"
vpc = true
}
resource "aws_route53_record" "cluster_base" {
zone_id = "${var.my_r53_zone}"
type = "CNAME"
name = "${var.my_instance_name}.${var.my_r53_domain}."
records = [
"${aws_instance.app.public_dns}"
]
depends_on = [
"aws_eip.app"
]
}
I've left out some (most) arguments above for brevity.
As you can see, I'm creating an EC2 instance, attaching an EIP to it, and then trying to create a CNAME record pointing to the public_dns of the instance. The problem is that the instance's public_dns attribute is empty when the aws_route53_record resource provisions (because I'm using
associate_public_ip_address = false), and the resource is not allowed to have an empty value for its records argument.
I get the following error on a terraform apply:
Error applying plan:
1 error(s) occurred:
* aws_route53_record.cluster_base: InvalidChangeBatch: Invalid Resource Record: FATAL problem: DomainNameEmpty encountered at
status code: 400, request id: 4c86cc78-9792-11e5-88cf-b3d969a424ae
I came up with a workaround
here -- basically having the EIP resource poll for the instance's public_dns until it's not empty, and adding that as a public_dns attribute to the EIP -- but I'm sure this isn't the right away to go about this.
Is there a simpler way to have the aws_instance refresh it's attributes *after* the aws_eip attaches to it, so that the route53 record gets the most up-to-date value of the instance's public_dns?
Thanks in advance!
Kent