I'm trying to deploy a NextJS app via Terraform however I can't seem to get the Route53 Zone to work. I have registered the domain via Route53 and have setup a hosted zone with that very domain. When using the CLI command aws route53 list-hosted-zones
I can successfully see the hosted zone there. However whenever trying to run terraform plan
I'm met with this issue:
Error: no matching Route53Zone found
on .terraform/modules/aws_static_site/main.tf line 1, in data "aws_route53_zone" "zone":
1: data "aws_route53_zone" "zone" {
Here is my tf file:
provider "aws" {
region = "eu-west-1"
profile = "rozzle-static-site"
}
module "aws_static_site" {
source = "dvargas92495/static-site/aws"
version = "1.2.0"
domain = "rozzle.co.uk"
secret = "REMOVED"
tags = {
Application = "rozzle-static-site"
}
}
provider "github" {
owner = "dvargas92495"
}
resource "github_actions_secret" "deploy_aws_access_key" {
repository = "static-site-demo"
secret_name = "DEPLOY_AWS_ACCESS_KEY_ID"
plaintext_value = module.aws_static_site.deploy-id
}
resource "github_actions_secret" "deploy_aws_access_secret" {
repository = "static-site-demo"
secret_name = "DEPLOY_AWS_SECRET_ACCESS_KEY"
plaintext_value = module.aws_static_site.deploy-secret
}
I can't figure out how this works. Hoping someone can help!
This appears to be a problem with the aws-static-site module. On line 22 of the module's main.tf, it does this:
zone_domain_names = {
for d in local.all_domains: d => join(".", slice(split(".", d), length(split(".", d)) - 2, length(split(".", d))))
}
And in your case it produces this:
local.zone_domain_names = {
"rozzle.co.uk" = "co.uk"
"www.rozzle.co.uk" = "co.uk"
}
Which it tries to use for the zone data block.
data "aws_route53_zone" "zone" {
for_each = toset(values(local.zone_domain_names))
name = "${each.value}."
}
This naturally fails, as you do not control the "co.uk" domain.
It appears that this module only handles second level domains, not third level domains. I would suggest opening a bug report for this module.
Also, as a quick and dirty fix, you can download the aws-static-site code and create a local module from the aws-static-site and modify the code to work only for third level domains by changing the number 2 to number 3 on line 23 of the main.tf:
zone_domain_names = {
for d in local.all_domains: d => join(".", slice(split(".", d), length(split(".", d)) - 3, length(split(".", d))))
}
NB. This local module will then only work for third level domains, not second level domains.