Skip to content

Commit

Permalink
Merge pull request #6 from nicholas-c/feature/options-cloudfront-comp…
Browse files Browse the repository at this point in the history
…ression

feat: adds default gzip and brotli compression, variables to allow disabling
  • Loading branch information
Tomdango authored Aug 7, 2023
2 parents 06a130e + 06f3739 commit db95da3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ locals {
}, var.cloudfront.hsts)
waf_logging_configuration = var.cloudfront.waf_logging_configuration
cache_policy = {
default_ttl = coalesce(try(var.cloudfront.cache_policy.default_ttl, null), 0)
min_ttl = coalesce(try(var.cloudfront.cache_policy.min_ttl, null), 0)
max_ttl = coalesce(try(var.cloudfront.cache_policy.max_ttl, null), 31536000)
default_ttl = coalesce(try(var.cloudfront.cache_policy.default_ttl, null), 0)
min_ttl = coalesce(try(var.cloudfront.cache_policy.min_ttl, null), 0)
max_ttl = coalesce(try(var.cloudfront.cache_policy.max_ttl, null), 31536000)
enable_accept_encoding_brotli = try(var.cloudfront.cache_policy.enable_accept_encoding_brotli, true)
enable_accept_encoding_gzip = try(var.cloudfront.cache_policy.enable_accept_encoding_gzip, true)
cookies_config = merge({
cookie_behavior = "all"
}, try(var.cloudfront.cache_policy.cookies_config, {}))
Expand Down
4 changes: 3 additions & 1 deletion modules/opennext-cloudfront/cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ resource "aws_cloudfront_cache_policy" "cache_policy" {
min_ttl = var.cache_policy.min_ttl
max_ttl = var.cache_policy.max_ttl


parameters_in_cache_key_and_forwarded_to_origin {
enable_accept_encoding_brotli = var.cache_policy.enable_accept_encoding_brotli
enable_accept_encoding_gzip = var.cache_policy.enable_accept_encoding_gzip

cookies_config {
cookie_behavior = var.cache_policy.cookies_config.cookie_behavior

Expand Down
8 changes: 5 additions & 3 deletions modules/opennext-cloudfront/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ variable "origin_request_policy" {

variable "cache_policy" {
type = object({
default_ttl = number
min_ttl = number
max_ttl = number
default_ttl = number
min_ttl = number
max_ttl = number
enable_accept_encoding_gzip = bool
enable_accept_encoding_brotli = bool
cookies_config = object({
cookie_behavior = string
items = optional(list(string))
Expand Down
8 changes: 5 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ variable "cloudfront" {
})))
}))
cache_policy = optional(object({
default_ttl = optional(number)
min_ttl = optional(number)
max_ttl = optional(number)
default_ttl = optional(number)
min_ttl = optional(number)
max_ttl = optional(number)
enable_accept_encoding_gzip = optional(bool)
enable_accept_encoding_brotli = optional(bool)
cookies_config = optional(object({
cookie_behavior = string
}))
Expand Down

0 comments on commit db95da3

Please sign in to comment.