Skip to content

Instantly share code, notes, and snippets.

@yogeshlonkar
Created July 9, 2021 15:06
Show Gist options
  • Save yogeshlonkar/8f4f80d7b5ca9ae817574f5f79bcd65d to your computer and use it in GitHub Desktop.
Save yogeshlonkar/8f4f80d7b5ca9ae817574f5f79bcd65d to your computer and use it in GitHub Desktop.
Cheap Static Hosting with AWS and Cloudflare
# other ACM, S3 resources
resource "aws_cloudfront_distribution" "site_distribution" {
enabled = true
is_ipv6_enabled = true
aliases = [var.site_name, "www.${var.site_name}"]
price_class = "PriceClass_100"
default_root_object = "index.html"
# ...
}
resource "cloudflare_record" "cert_validation" {
name = replace(tolist(aws_acm_certificate.lonkar_org.domain_validation_options)[0].resource_record_name, ".${var.site_name}.", "")
ttl = 3600
type = tolist(aws_acm_certificate.lonkar_org.domain_validation_options)[0].resource_record_type
value = trimsuffix(tolist(aws_acm_certificate.lonkar_org.domain_validation_options)[0].resource_record_value, ".")
zone_id = local.cloudflare_zone_id
proxied = false
}
resource "cloudflare_record" "lonkar_org" {
name = "@"
type = "CNAME"
value = aws_cloudfront_distribution.site_distribution.domain_name
zone_id = local.cloudflare_zone_id
}
resource "cloudflare_record" "www_lonkar_org" {
name = "www"
type = "CNAME"
value = aws_cloudfront_distribution.site_distribution.domain_name
zone_id = local.cloudflare_zone_id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment