terraform-aws-cloudfront-s3-cdn icon indicating copy to clipboard operation
terraform-aws-cloudfront-s3-cdn copied to clipboard

Route53 A records not created from aliases list when using aws_route53_zone data source

Open kwhitejr opened this issue 4 years ago • 3 comments

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

I used this module with a pre-existing Route53 Hosted Zone and ACM Certificate. I included aliases = [...] in my configuration, but Terraform did not create the expected A records in Route53.

Expected Behavior

Terraform would deploy an A record for each alias.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Here is the main.tf in relevant part
locals {
  domain_name = "example.com"
}

data "aws_route53_zone" "main" {
  name         = local.domain_name
  private_zone = false
}

data "aws_acm_certificate" "certificate" {
  domain      = local.domain_name
  types       = ["AMAZON_ISSUED"]
  most_recent = true
}

module "cloudfront-s3-cdn" {
  source  = "cloudposse/cloudfront-s3-cdn/aws"
  version = "0.35.0"

  name                 = local.domain_name
  origin_force_destroy = true
  encryption_enabled   = true

  # DNS Settings
  parent_zone_id      = data.aws_route53_zone.main.id
  acm_certificate_arn = data.aws_acm_certificate.certificate.arn
  aliases             = [local.domain_name, "www.${local.domain_name}"]
  ipv6_enabled        = true

  # Caching Settings
  default_ttl = 300
  compress    = true

  # Website settings
  website_enabled = true
  index_document  = "index.html"
  error_document  = "index.html"

  depends_on = [data.aws_acm_certificate.certificate]
}
  1. Run terraform apply
  2. Visit site

Additional Context

The module worked as expected except for the A records. I was able to visit the site via the CloudFront Distribution's *.cloudfront.net url. I manually added the Route53 A records and was able to visit the site via the aliases as expected.

kwhitejr avatar Oct 27 '20 02:10 kwhitejr

I encountered the same behaviour and setting dns_alias_enabled = true resolved it.

rayglover-ibm avatar Dec 12 '20 20:12 rayglover-ibm

Yep that makes sense. I'd say this issue is resolved

https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/blob/c7e6f3e6d1513157ca4c4e05379e39bd4dc20409/main.tf#L374-L377

nitrocode avatar Mar 27 '21 20:03 nitrocode

Hmm... could argue that if you pass in the var.parent_zone_name that the var.dns_alias_enabled is extraneous.

nitrocode avatar Mar 27 '21 21:03 nitrocode