2

Terraform v0.12.x

I'm trying to create a Route53 record with this script, which aims to create an A record that's aliased to an ALB.

data "aws_route53_zone" "mycompany_com" {
  name         = "mycompany.com."
  private_zone = true
}

resource "aws_route53_record" "jenkins_master_green" {
  zone_id = data.aws_route53_zone.mycompany_com.zone_id
  name    = "jenkins-green.${data.aws_route53_zone.mycompany_com.name}"
  type    = "A"
  alias {
    name = aws_lb.jenkins_master_green.dns_name
    zone_id = data.aws_route53_zone.mycompany_com.zone_id
    evaluate_target_health = false
  }
}

The plan shows the correct values I expect

$ terraform plan -out out.output

But when I apply the plan I get

$ terraform apply out.output
aws_route53_record.jenkins_master_green: Creating...

Error: [ERR]: Error building changeset: InvalidChangeBatch: [Tried to create an alias that targets <redacted>.us-east-1.elb.amazonaws.com., type A in zone <redacted>, but the alias target name does not lie within the target zone, Tried to create an alias that targets <redacted>.us-east-1.elb.amazonaws.com., type A in zone <redacted>, but that target was not found]
    status code: 400, request id: 2cf7384d-fa16-4828-854b-ea3e56cc0754

If I go to the AWS Route53 console, I can create the record. What am I missing?

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • I think this is a duplicate of https://stackoverflow.com/a/48926675/2291321. If you agree it might be useful to mark this as such so that people searching for this specific problem can see the answer more easily whichever way they end up at it from Google etc. – ydaetskcoR Nov 10 '20 at 10:48

1 Answers1

5

Try using zone_id from aws_lb.jenkins_master_green

data "aws_route53_zone" "mycompany_com" {
  name         = "mycompany.com."
  private_zone = true
}

resource "aws_route53_record" "jenkins_master_green" {
  zone_id = data.aws_route53_zone.mycompany_com.zone_id
  name    = "jenkins-green.${data.aws_route53_zone.mycompany_com.name}"
  type    = "A"
  alias {
    name                   = aws_lb.jenkins_master_green.dns_name
    zone_id                = aws_lb.jenkins_master_green.zone_id
    evaluate_target_health = false
  }
}
1efty
  • 825
  • 7
  • 10