Skip to content

Commit

Permalink
Add a custom domain to the personal website cloudfront distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansimsmith committed Nov 18, 2024
1 parent 7e6dfa2 commit 8316673
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion personal_website_web/infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ provider "aws" {
region = "ap-southeast-2"
}

provider "aws" {
alias = "us_east_1"
region = "us-east-1"
}

locals {
application_id = "personal_website_web"
origin_id = "${local.application_id}_s3_origin"
Expand Down Expand Up @@ -107,6 +112,18 @@ resource "aws_cloudfront_origin_access_control" "personal_website_web" {
signing_protocol = "sigv4"
}

resource "aws_acm_certificate" "personal_website_web" {
provider = aws.us_east_1
domain_name = "jordansimsmith.com"
validation_method = "DNS"

tags = local.tags

lifecycle {
create_before_destroy = true
}
}

resource "aws_cloudfront_distribution" "personal_website_web" {
origin {
domain_name = aws_s3_bucket.personal_website_web.bucket_regional_domain_name
Expand All @@ -119,6 +136,8 @@ resource "aws_cloudfront_distribution" "personal_website_web" {
default_root_object = "index.html"
price_class = "PriceClass_All"

aliases = ["jordansimsmith.com"]

default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
Expand All @@ -145,7 +164,9 @@ resource "aws_cloudfront_distribution" "personal_website_web" {
}

viewer_certificate {
cloudfront_default_certificate = true
acm_certificate_arn = aws_acm_certificate.personal_website_web.arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.2_2021"
}

tags = local.tags
Expand Down

0 comments on commit 8316673

Please sign in to comment.