From 06f37397fc2d672353add2596ead13cc09fbad0c Mon Sep 17 00:00:00 2001 From: Nicholas Carter Date: Fri, 4 Aug 2023 18:02:10 +0100 Subject: [PATCH] feat: adds default gzip and brotli compression, variables to allow disabling --- locals.tf | 8 +++++--- modules/opennext-cloudfront/cloudfront.tf | 4 +++- modules/opennext-cloudfront/variables.tf | 8 +++++--- variables.tf | 8 +++++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/locals.tf b/locals.tf index 128ba87..0a6731e 100644 --- a/locals.tf +++ b/locals.tf @@ -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, {})) diff --git a/modules/opennext-cloudfront/cloudfront.tf b/modules/opennext-cloudfront/cloudfront.tf index d04f1ab..36a1a6c 100644 --- a/modules/opennext-cloudfront/cloudfront.tf +++ b/modules/opennext-cloudfront/cloudfront.tf @@ -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 diff --git a/modules/opennext-cloudfront/variables.tf b/modules/opennext-cloudfront/variables.tf index 63e2d58..d3cea54 100644 --- a/modules/opennext-cloudfront/variables.tf +++ b/modules/opennext-cloudfront/variables.tf @@ -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)) diff --git a/variables.tf b/variables.tf index a4e6a12..527a965 100644 --- a/variables.tf +++ b/variables.tf @@ -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 }))