Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"no matching Route53Zone found": Terraform's Route53 data source is not recognizing the hosted zone name

Let's say that I have a public hosted zone names example.com.. I use the following piece of Terraform code to dynamically fetch the hosted zone id based on the name as per the docs.

data "aws_route53_zone" "main" {
  name = "example.com." # Notice the dot!!!
  private_zone = false
}

During terraform plan it comes up with this error:

Error refreshing state: 1 error(s) occurred:

* data.aws_route53_zone.main: no matching Route53Zone found

Is there a bug that I should report or am I missing something?

like image 310
Kostas Demiris Avatar asked Jan 13 '17 10:01

Kostas Demiris


1 Answers

The aws_route53_zone data source will list all the hosted zones in the account that Terraform has permissions to view.

If you are trying to reference a zone in another account then you can do this by creating a role/user in the account with the zone that has permissions to list all the zones (route53:ListHostedZones*,route53:GetHostedZone*) and then having a second "provider" be used for this data source.

So you might have something like this:

provider "aws" {
    # ... access keys etc/assume role block
}

# DNS account
provider "aws" {
    alias = "dns_zones"
    # ... access keys etc/assume role block
}

data "aws_route53_zone" "main" {
  provider = "aws.dns_zones"
  name = "example.com." # Notice the dot!!!
  private_zone = false
}

resource "aws_route53_record" "www" {
  zone_id = "${data.aws_route53_zone.main.zone_id}"
  name = "www.${data.aws_route53_zone.main.name}"
  ...
}
like image 113
ydaetskcoR Avatar answered Jan 04 '23 04:01

ydaetskcoR