Skip to content

Commit

Permalink
Set name of cache policies
Browse files Browse the repository at this point in the history
  • Loading branch information
pjuniorlima committed Mar 29, 2021
1 parent 559083f commit 1eb0900
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions site-main/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ resource "aws_cloudfront_distribution" "website_cdn" {
}
}

cache_policy_id = var.enable_cache_policy == true ? aws_cloudfront_cache_policy.main[0].id : null
origin_request_policy_id = var.enable_cache_policy == true ? aws_cloudfront_origin_request_policy.main[0].id : null
cache_policy_id = var.enable_cache_policy == true ? "S3-CORS-Caching" : null
origin_request_policy_id = var.enable_cache_policy == true ? "Managed-CORS-S3Origin" : null

forwarded_values {
query_string = var.forward-query-string
Expand Down Expand Up @@ -234,50 +234,50 @@ resource "aws_cloudfront_origin_access_identity" "origin_access_identity" {
## Cache Policy
################################################################################################################

resource "aws_cloudfront_cache_policy" "main" {
count = var.enable_cache_policy == true ? 1 : 0

name = "behavior-s3-cors-Cache"
default_ttl = var.cache_policy_default_ttl
max_ttl = var.cache_policy_max_ttl
min_ttl = var.cache_policy_min_ttl

parameters_in_cache_key_and_forwarded_to_origin {
headers_config {
header_behavior = "whitelist"
headers {
items = ["origin"]
}
}
cookies_config {
cookie_behavior = "none"
}
query_strings_config {
query_string_behavior = "all"
}
}
}
# resource "aws_cloudfront_cache_policy" "main" {
# count = var.enable_cache_policy == true ? 1 : 0
#
# name = "behavior-s3-cors-Cache"
# default_ttl = var.cache_policy_default_ttl
# max_ttl = var.cache_policy_max_ttl
# min_ttl = var.cache_policy_min_ttl
#
# parameters_in_cache_key_and_forwarded_to_origin {
# headers_config {
# header_behavior = "whitelist"
# headers {
# items = ["origin"]
# }
# }
# cookies_config {
# cookie_behavior = "none"
# }
# query_strings_config {
# query_string_behavior = "all"
# }
# }
# }

################################################################################################################
## Origin Request Policy
################################################################################################################

resource "aws_cloudfront_origin_request_policy" "main" {
count = var.enable_cache_policy == true ? 1 : 0

name = "behavior-managed-cors-s3-origin"
comment = "Policy for S3 origin with CORS"

headers_config {
header_behavior = "whitelist"
headers {
items = ["origin", "access-control-request-headers", "access-control-request-method"]
}
}
cookies_config {
cookie_behavior = "none"
}
query_strings_config {
query_string_behavior = "none"
}
}
#
# resource "aws_cloudfront_origin_request_policy" "main" {
# count = var.enable_cache_policy == true ? 1 : 0
#
# name = "behavior-managed-cors-s3-origin"
# comment = "Policy for S3 origin with CORS"
#
# headers_config {
# header_behavior = "whitelist"
# headers {
# items = ["origin", "access-control-request-headers", "access-control-request-method"]
# }
# }
# cookies_config {
# cookie_behavior = "none"
# }
# query_strings_config {
# query_string_behavior = "none"
# }
# }

0 comments on commit 1eb0900

Please sign in to comment.