diff --git a/README.md b/README.md index f1c45ad5..62907573 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,7 @@ Available targets: | [allowed\_methods](#input\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | `list(string)` |
[
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PATCH",
"POST",
"PUT"
]
| no | | [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | [block\_origin\_public\_access\_enabled](#input\_block\_origin\_public\_access\_enabled) | When set to 'true' the s3 origin bucket will have public access block enabled | `bool` | `false` | no | +| [cache\_policy\_id](#input\_cache\_policy\_id) | The unique identifier of the cache policy that is attached to the default cache behavior | `string` | `null` | no | | [cached\_methods](#input\_cached\_methods) | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET",
"HEAD"
]
| no | | [cloudfront\_origin\_access\_identity\_iam\_arn](#input\_cloudfront\_origin\_access\_identity\_iam\_arn) | Existing cloudfront origin access identity iam arn that is supplied in the s3 bucket policy | `string` | `""` | no | | [cloudfront\_origin\_access\_identity\_path](#input\_cloudfront\_origin\_access\_identity\_path) | Existing cloudfront origin access identity path used in the cloudfront distribution's s3\_origin\_config content | `string` | `""` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 3bf13995..3c302266 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -49,6 +49,7 @@ | [allowed\_methods](#input\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | `list(string)` |
[
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"PATCH",
"POST",
"PUT"
]
| no | | [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | | [block\_origin\_public\_access\_enabled](#input\_block\_origin\_public\_access\_enabled) | When set to 'true' the s3 origin bucket will have public access block enabled | `bool` | `false` | no | +| [cache\_policy\_id](#input\_cache\_policy\_id) | The unique identifier of the cache policy that is attached to the default cache behavior | `string` | `null` | no | | [cached\_methods](#input\_cached\_methods) | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET",
"HEAD"
]
| no | | [cloudfront\_origin\_access\_identity\_iam\_arn](#input\_cloudfront\_origin\_access\_identity\_iam\_arn) | Existing cloudfront origin access identity iam arn that is supplied in the s3 bucket policy | `string` | `""` | no | | [cloudfront\_origin\_access\_identity\_path](#input\_cloudfront\_origin\_access\_identity\_path) | Existing cloudfront origin access identity path used in the cloudfront distribution's s3\_origin\_config content | `string` | `""` | no | diff --git a/main.tf b/main.tf index 3733e605..b5f5a667 100644 --- a/main.tf +++ b/main.tf @@ -302,17 +302,22 @@ resource "aws_cloudfront_distribution" "default" { default_cache_behavior { allowed_methods = var.allowed_methods cached_methods = var.cached_methods + cache_policy_id = var.cache_policy_id target_origin_id = module.this.id compress = var.compress trusted_signers = var.trusted_signers - forwarded_values { - query_string = var.forward_query_string - query_string_cache_keys = var.query_string_cache_keys - headers = var.forward_header_values + dynamic "forwarded_values" { + # If a cache policy is specified, we cannot include a `forwarded_values` block at all in the API request + for_each = var.cache_policy_id == null ? [true] : [] + content { + query_string = var.forward_query_string + query_string_cache_keys = var.query_string_cache_keys + headers = var.forward_header_values - cookies { - forward = var.forward_cookies + cookies { + forward = var.forward_cookies + } } } diff --git a/variables.tf b/variables.tf index 3e669954..6aead6f6 100644 --- a/variables.tf +++ b/variables.tf @@ -197,6 +197,12 @@ variable "cached_methods" { description = "List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD)" } +variable "cache_policy_id" { + type = string + default = null + description = "The unique identifier of the cache policy that is attached to the default cache behavior" +} + variable "default_ttl" { type = number default = 60