cloudposse / terraform-aws-cloudfront-s3-cdn

Terraform module to easily provision CloudFront CDN backed by an S3 origin
https://cloudposse.com/accelerate
Apache License 2.0
274 stars 247 forks source link

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

Open kwhitejr opened 3 years ago

kwhitejr commented 3 years ago

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] }


2. Run `terraform apply`
3. 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.
rayglover-ibm commented 3 years ago

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

nitrocode commented 3 years ago

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 commented 3 years ago

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