Created
May 3, 2019 01:42
-
-
Save catvec/9a549b703e8117397f11c2e79c5ea08f to your computer and use it in GitHub Desktop.
Terraform configuration to create a multi domain ACM CloudFront Distribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SSL Certificate | |
resource "aws_acm_certificate" "personal-website" { | |
domain_name = "${aws_route53_zone.4e48-dev.name}" | |
subject_alternative_names = [ | |
"${aws_route53_zone.noahh-io.name}" | |
] | |
validation_method = "DNS" | |
tags = { | |
Name = "personal-website" | |
} | |
} | |
resource "aws_route53_record" "4e48-dev-personal-website-acm-proof" { | |
zone_id = "${aws_route53_zone.4e48-dev.id}" | |
name = "${aws_acm_certificate.personal-website.domain_validation_options.0.resource_record_name}" | |
type = "${aws_acm_certificate.personal-website.domain_validation_options.0.resource_record_type}" | |
records = [ | |
"${aws_acm_certificate.personal-website.domain_validation_options.0.resource_record_value}" | |
] | |
ttl = "60" | |
} | |
resource "aws_route53_record" "noahh-io-personal-website-acm-proof" { | |
zone_id = "${aws_route53_zone.noahh-io.id}" | |
name = "${aws_acm_certificate.personal-website.domain_validation_options.1.resource_record_name}" | |
type = "${aws_acm_certificate.personal-website.domain_validation_options.1.resource_record_type}" | |
records = [ | |
"${aws_acm_certificate.personal-website.domain_validation_options.1.resource_record_value}" | |
] | |
ttl = "60" | |
} | |
# Distribution | |
variable "personal_website_content_bucket_prefix" { | |
type = "string" | |
description = "Prefix in content bucket to serve files for my personal website" | |
default = "/NoahHuppert.com" | |
} | |
resource "aws_cloudfront_distribution" "personal-website" { | |
origin { | |
domain_name = "${aws_s3_bucket.web-content.bucket_regional_domain_name}" | |
origin_id = "${aws_s3_bucket.web-content.bucket}" | |
origin_path = "${var.personal_website_content_bucket_prefix}" | |
} | |
enabled = true | |
is_ipv6_enabled = true | |
default_root_object = "index.html" | |
aliases = [ | |
"${var.domain_4e48_dev_name}", | |
"${var.domain_noahh_io_name}" | |
] | |
default_cache_behavior { | |
allowed_methods = [ "HEAD", "OPTIONS", "GET" ] | |
cached_methods = [ "HEAD", "GET" ] | |
target_origin_id = "${aws_s3_bucket.web-content.bucket}" | |
viewer_protocol_policy = "allow-all" | |
min_ttl = 0 | |
default_ttl = 60 | |
max_ttl = 3600 | |
forwarded_values { | |
query_string = true | |
cookies { | |
forward = "none" | |
} | |
} | |
} | |
restrictions { | |
geo_restriction { | |
restriction_type = "none" | |
} | |
} | |
viewer_certificate { | |
acm_certificate_arn = "${aws_acm_certificate.personal-website.arn}" | |
ssl_support_method = "sni-only" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment