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?
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}"
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With