hashicorp / learn-terraform-cloudflare-static-website

https://learn.hashicorp.com/tutorials/terraform/cloudflare-static-website
Mozilla Public License 2.0
21 stars 19 forks source link

Terraform acm-cloudfront branch still contains cloudflare code #7

Open Francisco-RP opened 2 years ago

Francisco-RP commented 2 years ago

https://github.com/hashicorp/learn-terraform-cloudflare-static-website/blob/acm-cloudfront/main.tf

The acm-cloudfront branch uses ACM for SSL certificate and Cloudfront for CDN. This configuration is more complex and works even if your S3 bucket name is already taken.

If this branch is supposed to be a setup for CloudFront, curious why this still contains CloudFlare code in it? Is that still needed?

provider "cloudflare" {}

...

data "cloudflare_zones" "domain" {
  filter {
    name = var.site_domain
  }
}

resource "cloudflare_record" "acm" {
  zone_id = data.cloudflare_zones.domain.zones[0].id

  // Cloudflare doesn't support `allow_overwrite` field like the route53_record 
  // resource; as a result, this configuration hardcodes the first record to 
  // verify the ACM certificate.
  // for_each = {
  //   for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
  //     name   = dvo.resource_record_name
  //     record = dvo.resource_record_value
  //     type   = dvo.resource_record_type
  //   }
  // }

  name  = aws_acm_certificate.cert.domain_validation_options.*.resource_record_name[0]
  type  = aws_acm_certificate.cert.domain_validation_options.*.resource_record_type[0]
  value = trimsuffix(aws_acm_certificate.cert.domain_validation_options.*.resource_record_value[0], ".")

  // Must be set to false. ACM validation false otherwise
  proxied = false
}

...

resource "cloudflare_record" "site_cname" {
  zone_id = data.cloudflare_zones.domain.zones[0].id
  name    = var.site_domain
  value   = aws_cloudfront_distribution.dist.domain_name
  type    = "CNAME"

  ttl     = 1
  proxied = true
}

resource "cloudflare_record" "www" {
  zone_id = data.cloudflare_zones.domain.zones[0].id
  name    = "www"
  value   = aws_cloudfront_distribution.dist.domain_name
  type    = "CNAME"

  ttl     = 1
  proxied = true
}
Alevale commented 11 months ago

The same is true for their tutorial, if you try to read the "CloudFront" part of it you'll see it's full of other CloudFlare explanations.

Although they do help to understand what has to happen they feel pretty confusing.