Skip to content

Commit

Permalink
Merge pull request #8 from hahuang65/master
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanio authored Jun 14, 2021
2 parents 53f6aa9 + c1931d8 commit f5960c6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions certificate.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ provider "aws" {
}

data "aws_acm_certificate" "frontend" {
provider = "aws.us-east-1"
domain = "${coalesce(var.wildcard_ssl, var.hostname)}"
provider = aws.us-east-1
domain = coalesce(var.wildcard_ssl, var.hostname)
}
24 changes: 12 additions & 12 deletions cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ resource "aws_cloudfront_distribution" "website" {
is_ipv6_enabled = true
http_version = "http2"

aliases = ["${compact(concat(list(var.hostname),var.aliases))}"]
aliases = compact(concat(tolist([var.hostname]), var.aliases))

viewer_certificate {
acm_certificate_arn = "${data.aws_acm_certificate.frontend.arn}"
acm_certificate_arn = data.aws_acm_certificate.frontend.arn
minimum_protocol_version = "TLSv1"
ssl_support_method = "sni-only"
}

origin {
domain_name = "${aws_s3_bucket.content.bucket_domain_name}"
origin_id = "${aws_s3_bucket.content.id}"
domain_name = aws_s3_bucket.content.bucket_domain_name
origin_id = aws_s3_bucket.content.id

s3_origin_config {
origin_access_identity = "${aws_cloudfront_origin_access_identity.website.cloudfront_access_identity_path}"
origin_access_identity = aws_cloudfront_origin_access_identity.website.cloudfront_access_identity_path
}
}

Expand All @@ -25,14 +25,14 @@ resource "aws_cloudfront_distribution" "website" {
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${aws_s3_bucket.content.id}"
target_origin_id = aws_s3_bucket.content.id

compress = true
viewer_protocol_policy = "redirect-to-https"

default_ttl = "${var.cache_ttl}"
min_ttl = "${(var.cache_ttl / 4) < 60 ? 0 : floor(var.cache_ttl / 4)}"
max_ttl = "${floor(var.cache_ttl * 24)}"
default_ttl = var.cache_ttl
min_ttl = (var.cache_ttl / 4) < 60 ? 0 : floor(var.cache_ttl / 4)
max_ttl = floor(var.cache_ttl * 24)

forwarded_values {
query_string = false
Expand All @@ -48,7 +48,7 @@ resource "aws_cloudfront_distribution" "website" {
// 100: Limit to only Europe, USA, and Canada endpoints.
// 200: + Hong Kong, Philippines, South Korea, Singapore, & Taiwan.
// All: + South America, and Australa.
price_class = "${var.price_class}"
price_class = var.price_class

restrictions {
geo_restriction {
Expand All @@ -58,11 +58,11 @@ resource "aws_cloudfront_distribution" "website" {

logging_config {
include_cookies = false
bucket = "${aws_s3_bucket.logs.bucket_domain_name}"
bucket = aws_s3_bucket.logs.bucket_domain_name
prefix = "${var.hostname}/cloudfront"
}

tags = "${merge(var.tags, map("Name", format("s3-cloudfront-%s-distribution", var.name)))}"
tags = merge(var.tags, tomap({ "Name" = format("s3-cloudfront-%s-distribution", var.name) }))
}

resource "aws_cloudfront_origin_access_identity" "website" {
Expand Down
4 changes: 2 additions & 2 deletions examples/policies/groups.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "aws_iam_group" "content_upload" {

resource "aws_iam_group_policy" "content_upload" {
name = "WebsiteDeveloperAccess"
group = "${aws_iam_group.content_upload.id}"
group = aws_iam_group.content_upload.id

policy = "${data.aws_iam_policy_document.content_upload.json}"
policy = data.aws_iam_policy_document.content_upload.json
}
8 changes: 4 additions & 4 deletions examples/policies/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
output "hostname" {
value = "${module.website.hostname}"
value = module.website.hostname
}

output "s3_bucket_name" {
value = "${module.website.s3_bucket_name}"
value = module.website.s3_bucket_name
}

output "cloudfront_distribution_id" {
value = "${module.website.cloudfront_distribution_id}"
value = module.website.cloudfront_distribution_id
}

output "cloudfront_distribution_hostname" {
value = "${module.website.cloudfront_distribution_hostname}"
value = module.website.cloudfront_distribution_hostname
}
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ output "hostname" {

output "s3_bucket_name" {
description = "The name of the S3 content bucket to upload the website content to."
value = "${aws_s3_bucket.content.id}"
value = aws_s3_bucket.content.id
}

output "s3_logging_name" {
description = "The name of the S3 logging bucket that access logs will be saved to."
value = "${aws_s3_bucket.logs.id}"
value = aws_s3_bucket.logs.id
}

output "cloudfront_distribution_id" {
description = "The ID of the CloudFront Distribution."
value = "${aws_cloudfront_distribution.website.id}"
value = aws_cloudfront_distribution.website.id
}

output "cloudfront_distribution_hostname" {
description = "The hostname of the CloudFront Distribution (use for DNS CNAME)."
value = "${aws_cloudfront_distribution.website.domain_name}"
value = aws_cloudfront_distribution.website.domain_name
}

output "cloudfront_zone_id" {
description = "The Zone ID of the CloudFront Distribution (use for DNS Alias)."
value = "${aws_cloudfront_distribution.website.hosted_zone_id}"
value = aws_cloudfront_distribution.website.hosted_zone_id
}
22 changes: 11 additions & 11 deletions s3-content.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
resource "aws_s3_bucket" "content" {
bucket = "s3-cloudfront-${lower(var.name)}-content"
acl = "public-read"
force_destroy = "${var.force_destroy}"
force_destroy = var.force_destroy

versioning {
enabled = true
}

website {
index_document = "${var.index_document}"
error_document = "${var.error_document}"
index_document = var.index_document
error_document = var.error_document
}

cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD"]
allowed_origins = ["https://${var.hostname}"]
expose_headers = ["ETag"]
max_age_seconds = "${var.cache_ttl}"
max_age_seconds = var.cache_ttl
}

lifecycle_rule {
Expand All @@ -30,16 +30,16 @@ resource "aws_s3_bucket" "content" {
}

logging {
target_bucket = "${aws_s3_bucket.logs.id}"
target_bucket = aws_s3_bucket.logs.id
target_prefix = "${var.hostname}/s3"
}

tags = "${merge(var.tags, map("Name", format("s3-cloudfront-%s-content", var.name)))}"
tags = merge(var.tags, tomap({ "Name" = format("s3-cloudfront-%s-content", var.name) }))
}

resource "aws_s3_bucket_policy" "content" {
bucket = "${aws_s3_bucket.content.id}"
policy = "${data.aws_iam_policy_document.s3_bucket_content.json}"
bucket = aws_s3_bucket.content.id
policy = data.aws_iam_policy_document.s3_bucket_content.json
}

data "aws_iam_policy_document" "s3_bucket_content" {
Expand All @@ -52,7 +52,7 @@ data "aws_iam_policy_document" "s3_bucket_content" {

principals {
type = "AWS"
identifiers = ["${aws_cloudfront_origin_access_identity.website.iam_arn}"]
identifiers = [aws_cloudfront_origin_access_identity.website.iam_arn]
}
}

Expand All @@ -61,11 +61,11 @@ data "aws_iam_policy_document" "s3_bucket_content" {
effect = "Allow"

actions = ["s3:ListBucket"]
resources = ["${aws_s3_bucket.content.arn}"]
resources = [aws_s3_bucket.content.arn]

principals {
type = "AWS"
identifiers = ["${aws_cloudfront_origin_access_identity.website.iam_arn}"]
identifiers = [aws_cloudfront_origin_access_identity.website.iam_arn]
}
}
}
10 changes: 5 additions & 5 deletions s3-logs.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
resource "aws_s3_bucket" "logs" {
bucket = "s3-cloudfront-${lower(var.name)}-logs"
acl = "log-delivery-write"
force_destroy = "${var.force_destroy}"
force_destroy = var.force_destroy

lifecycle_rule {
id = "s3-cloudfront-${lower(var.name)}-logs-transitions"
enabled = true

transition {
days = "${var.logs_transition_ia}"
days = var.logs_transition_ia
storage_class = "STANDARD_IA"
}

transition {
days = "${var.logs_transition_glacier}"
days = var.logs_transition_glacier
storage_class = "GLACIER"
}

expiration {
days = "${var.logs_expiration}"
days = var.logs_expiration
}
}

tags = "${merge(var.tags, map("Name", format("s3-cloudfront-%s-logs", var.name)))}"
tags = merge(var.tags, tomap({ "Name" = format("s3-cloudfront-%s-logs", var.name) }))
}
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ variable "tags" {

variable "force_destroy" {
description = "A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable."
default = "false"
default = false
}

0 comments on commit f5960c6

Please sign in to comment.