-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CloudFront Terraform infrastructure
Adds the necessary files and changes to the Terraform infrastructure to create a CloudFront distribution to serve Anejo content using HTTPS and a CDN.
- Loading branch information
1 parent
6ed68f0
commit 1a10a4f
Showing
5 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
### Anejo – CloudFront Distribution ### | ||
|
||
|
||
locals { | ||
anejo_s3_origin_id = "AnejoS3Origin" | ||
} | ||
|
||
|
||
|
||
resource "aws_cloudfront_origin_access_identity" "anejo_distribution_identity" { | ||
comment = "Origin Access Identity for Anejo S3 bucket origin." | ||
} | ||
|
||
|
||
# CloudFront Distribution | ||
resource "aws_cloudfront_distribution" "anejo_distribution" { | ||
origin { | ||
domain_name = "${aws_s3_bucket.anejo_repo_bucket.bucket_regional_domain_name}" | ||
origin_id = "${local.anejo_s3_origin_id}" | ||
origin_path = "/html" | ||
|
||
s3_origin_config { | ||
origin_access_identity = "${aws_cloudfront_origin_access_identity.anejo_distribution_identity.cloudfront_access_identity_path}" | ||
} | ||
} | ||
|
||
enabled = true | ||
is_ipv6_enabled = true | ||
comment = "Anejo CloudFront distribution" | ||
|
||
logging_config { | ||
include_cookies = false | ||
bucket = "${aws_s3_bucket.anejo_repo_bucket.bucket_domain_name}", | ||
prefix = "logs/distribution/" | ||
} | ||
|
||
aliases = "${var.anejo_distribution_aliases}" | ||
|
||
default_cache_behavior { | ||
allowed_methods = ["GET", "HEAD"] | ||
cached_methods = ["GET", "HEAD"] | ||
target_origin_id = "${local.anejo_s3_origin_id}" | ||
|
||
forwarded_values { | ||
query_string = false | ||
|
||
cookies { | ||
forward = "none" | ||
} | ||
} | ||
|
||
viewer_protocol_policy = "allow-all" | ||
min_ttl = 0 | ||
default_ttl = 3600 | ||
max_ttl = 86400 | ||
} | ||
|
||
# Cache behavior for catalogs | ||
ordered_cache_behavior { | ||
path_pattern = "*.sucatalog" | ||
allowed_methods = ["GET", "HEAD"] | ||
cached_methods = ["GET", "HEAD"] | ||
target_origin_id = "${local.anejo_s3_origin_id}" | ||
|
||
forwarded_values { | ||
query_string = false | ||
|
||
cookies { | ||
forward = "none" | ||
} | ||
} | ||
|
||
viewer_protocol_policy = "allow-all" | ||
min_ttl = 0 | ||
default_ttl = 600 | ||
max_ttl = 3600 | ||
} | ||
|
||
restrictions { | ||
geo_restriction { | ||
restriction_type = "whitelist" | ||
locations = "${var.anejo_distribution_geo_restriction_whitelist}" | ||
} | ||
} | ||
|
||
viewer_certificate { | ||
cloudfront_default_certificate = true | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
### Anejo – S3 Buckets ### | ||
|
||
# Repo S3 Bucket | ||
# Anejo Repo S3 Bucket | ||
resource "aws_s3_bucket" "anejo_repo_bucket" { | ||
bucket = "${var.anejo_repo_bucket}" | ||
acl = "private" | ||
force_destroy = true | ||
} | ||
|
||
|
||
# Anejo S3 Bucket Policy | ||
resource "aws_s3_bucket_policy" "anejo_s3_bucket_policy" { | ||
bucket = "${aws_s3_bucket.anejo_repo_bucket.id}" | ||
policy = "${data.aws_iam_policy_document.anejo_s3_bucket_policy_document.json}" | ||
} |