Skip to content

Commit

Permalink
af
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamv108 committed Feb 7, 2024
1 parent 98e6489 commit 439b440
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 161 deletions.
4 changes: 3 additions & 1 deletion infra/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module "app_aws_s3_buckets" {
source = "./modules/aws/s3/buckets"
}

#module "project_aws_cloudfront_distribution" {
#module "app_aws_cloudfront_distribution" {
# source = "./modules/aws/cloudfront/distribution"
# aws_s3_bucket_id_document = module.app_aws_s3_buckets.aws_s3_bucket_id_documents
# aws_s3_bucket_id_paste = module.app_aws_s3_buckets.aws_s3_bucket_id_paste
#}
200 changes: 100 additions & 100 deletions infra/app/modules/aws/cloudfront/distribution/documentssstore.tf
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
#resource "aws_cloudfront_distribution" "s3_distribution" {
# origin {
# domain_name = aws_s3_bucket.b.bucket_regional_domain_name
# origin_access_control_id = aws_cloudfront_origin_access_control.default.id
# origin_id = local.s3_origin_id
# }
#
# enabled = true
# is_ipv6_enabled = true
# comment = "Some comment"
#
# logging_config {
# include_cookies = false
# bucket = "mylogs.s3.amazonaws.com"
# prefix = "myprefix"
# }
#
# aliases = ["mysite.example.com", "yoursite.example.com"]
#
# default_cache_behavior {
# allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
# cached_methods = ["GET", "HEAD"]
# target_origin_id = local.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 with precedence 0
# ordered_cache_behavior {
# path_pattern = "/content/immutable/*"
# allowed_methods = ["GET", "HEAD", "OPTIONS"]
# cached_methods = ["GET", "HEAD", "OPTIONS"]
# target_origin_id = local.s3_origin_id
#
# forwarded_values {
# query_string = false
# headers = ["Origin"]
#
# cookies {
# forward = "none"
# }
# }
#
# min_ttl = 0
# default_ttl = 86400
# max_ttl = 31536000
# compress = true
# viewer_protocol_policy = "redirect-to-https"
# }
#
# # Cache behavior with precedence 1
# ordered_cache_behavior {
# path_pattern = "/content/*"
# allowed_methods = ["GET", "HEAD", "OPTIONS"]
# cached_methods = ["GET", "HEAD"]
# target_origin_id = local.s3_origin_id
#
# forwarded_values {
# query_string = false
#
# cookies {
# forward = "none"
# }
# }
#
# min_ttl = 0
# default_ttl = 3600
# max_ttl = 86400
# compress = true
# viewer_protocol_policy = "redirect-to-https"
# }
#
# price_class = "PriceClass_200"
#
# restrictions {
# geo_restriction {
# restriction_type = "whitelist"
# locations = ["US", "CA", "GB", "DE"]
# }
# }
#
# tags = {
# Environment = "${var.environment}"
# }
#
# viewer_certificate {
# cloudfront_default_certificate = true
# }
#}
resource "aws_cloudfront_distribution" "s3_distribution" {
origin {
domain_name = aws_s3_bucket.b.bucket_regional_domain_name
origin_access_control_id = aws_cloudfront_origin_access_control.default.id
origin_id = "${var.aws_s3_bucket_id_document}"
}

enabled = true
is_ipv6_enabled = true
comment = "Some comment"

logging_config {
include_cookies = false
bucket = "mylogs.s3.amazonaws.com"
prefix = "myprefix"
}

aliases = ["mysite.example.com", "yoursite.example.com"]

default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${var.aws_s3_bucket_id_document}"

forwarded_values {
query_string = false

cookies {
forward = "none"
}
}

viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}

# Cache behavior with precedence 0
ordered_cache_behavior {
path_pattern = "/content/immutable/*"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD", "OPTIONS"]
target_origin_id = local.s3_origin_id

forwarded_values {
query_string = false
headers = ["Origin"]

cookies {
forward = "none"
}
}

min_ttl = 0
default_ttl = 86400
max_ttl = 31536000
compress = true
viewer_protocol_policy = "redirect-to-https"
}

# Cache behavior with precedence 1
ordered_cache_behavior {
path_pattern = "/content/*"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = local.s3_origin_id

forwarded_values {
query_string = false

cookies {
forward = "none"
}
}

min_ttl = 0
default_ttl = 3600
max_ttl = 86400
compress = true
viewer_protocol_policy = "redirect-to-https"
}

price_class = "PriceClass_200"

restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = ["US", "CA", "GB", "DE"]
}
}

tags = {
Environment = "${var.environment}"
}

viewer_certificate {
cloudfront_default_certificate = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#resource "aws_cloudfront_origin_access_control" "oac" {
# name = "${var.name}-oac"
# description = "${var.name}-Origine Access Control Policy"
# origin_access_control_origin_type = "s3"
# signing_behavior = "always"
# signing_protocol = "sigv4"
#}
12 changes: 12 additions & 0 deletions infra/app/modules/aws/cloudfront/distribution/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ variable "environment" {

default = "test"
}

variable "aws_s3_bucket_id_document" {
type = string
description = "AWS region for all resources."
default = ""
}

variable "aws_s3_bucket_id_paste" {
type = string
description = "AWS region for all resources."
default = ""
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "aws_s3_bucket" "documentssstore" {
resource "aws_s3_bucket" "document" {
bucket = "documentssstore"

tags = {
Expand All @@ -10,14 +10,14 @@ resource "aws_s3_bucket" "documentssstore" {
}

resource "aws_s3_bucket_policy" "documentssstore_allow_access_from_cloudfront" {
bucket = aws_s3_bucket.documentssstore.id
bucket = aws_s3_bucket.document.id
policy = data.aws_iam_policy_document.documentssstore_allow_access_from_cloudfront.json
}

data "aws_iam_policy_document" "documentssstore_allow_access_from_cloudfront" {
statement {
principals {
type = "AWS"
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}

Expand All @@ -26,8 +26,8 @@ data "aws_iam_policy_document" "documentssstore_allow_access_from_cloudfront" {
]

resources = [
aws_s3_bucket.documentssstore.arn,
"${aws_s3_bucket.documentssstore.arn}/*",
aws_s3_bucket.document.arn,
"${aws_s3_bucket.document.arn}/*",
]

condition {
Expand Down
9 changes: 9 additions & 0 deletions infra/app/modules/aws/s3/buckets/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "aws_s3_bucket_id_documents" {
value = aws_s3_bucket.document.id
description = "aws_s3_bucket_id_documents"
}

output "aws_s3_bucket_id_paste" {
value = aws_s3_bucket.paste.id
description = "aws_s3_bucket_id_documents"
}
39 changes: 39 additions & 0 deletions infra/app/modules/aws/s3/buckets/paste.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resource "aws_s3_bucket" "paste" {
bucket = "${var.s3_bucket_paste}"

tags = {
Name = "${var.s3_bucket_paste}"
Owner = "${var.project_name}"
Environment = "${var.environment}"
Region = "${var.region}"
}
}

resource "aws_s3_bucket_policy" "pastesss_allow_access_from_cloudfront" {
bucket = aws_s3_bucket.paste.id
policy = data.aws_iam_policy_document.pastesss_allow_access_from_cloudfront.json
}

data "aws_iam_policy_document" "pastesss_allow_access_from_cloudfront" {
statement {
principals {
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}

actions = [
"s3:GetObject",
]

resources = [
aws_s3_bucket.paste.arn,
"${aws_s3_bucket.paste.arn}/*",
]

condition {
test = "StringEquals"
values = ["arn:aws:cloudfront::430689894701:distribution/E2ZI5IWQWTVER"]
variable = "AWS:SourceArn"
}
}
}
6 changes: 6 additions & 0 deletions infra/app/modules/aws/s3/buckets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ variable "environment" {

default = "test"
}

variable "s3_bucket_paste" {
type = string
description = "Template service in java, spring-boot project."
default = "private-pastesss"
}
Loading

0 comments on commit 439b440

Please sign in to comment.