Skip to content

Commit 2efb943

Browse files
dmattiacloudpossebotactions-botnitrocode
authored
Add support for a custom cache policy (#140)
* Add support for a custom cache policy Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: actions-bot <[email protected]> Co-authored-by: nitro <[email protected]>
1 parent f6c3ce2 commit 2efb943

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ Available targets:
275275
| <a name="input_allowed_methods"></a> [allowed\_methods](#input\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | `list(string)` | <pre>[<br> "DELETE",<br> "GET",<br> "HEAD",<br> "OPTIONS",<br> "PATCH",<br> "POST",<br> "PUT"<br>]</pre> | no |
276276
| <a name="input_attributes"></a> [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
277277
| <a name="input_block_origin_public_access_enabled"></a> [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 |
278+
| <a name="input_cache_policy_id"></a> [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 |
278279
| <a name="input_cached_methods"></a> [cached\_methods](#input\_cached\_methods) | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` | <pre>[<br> "GET",<br> "HEAD"<br>]</pre> | no |
279280
| <a name="input_cloudfront_origin_access_identity_iam_arn"></a> [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 |
280281
| <a name="input_cloudfront_origin_access_identity_path"></a> [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 |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
| <a name="input_allowed_methods"></a> [allowed\_methods](#input\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) for AWS CloudFront | `list(string)` | <pre>[<br> "DELETE",<br> "GET",<br> "HEAD",<br> "OPTIONS",<br> "PATCH",<br> "POST",<br> "PUT"<br>]</pre> | no |
5050
| <a name="input_attributes"></a> [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
5151
| <a name="input_block_origin_public_access_enabled"></a> [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 |
52+
| <a name="input_cache_policy_id"></a> [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 |
5253
| <a name="input_cached_methods"></a> [cached\_methods](#input\_cached\_methods) | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` | <pre>[<br> "GET",<br> "HEAD"<br>]</pre> | no |
5354
| <a name="input_cloudfront_origin_access_identity_iam_arn"></a> [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 |
5455
| <a name="input_cloudfront_origin_access_identity_path"></a> [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 |

main.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,22 @@ resource "aws_cloudfront_distribution" "default" {
302302
default_cache_behavior {
303303
allowed_methods = var.allowed_methods
304304
cached_methods = var.cached_methods
305+
cache_policy_id = var.cache_policy_id
305306
target_origin_id = module.this.id
306307
compress = var.compress
307308
trusted_signers = var.trusted_signers
308309

309-
forwarded_values {
310-
query_string = var.forward_query_string
311-
query_string_cache_keys = var.query_string_cache_keys
312-
headers = var.forward_header_values
310+
dynamic "forwarded_values" {
311+
# If a cache policy is specified, we cannot include a `forwarded_values` block at all in the API request
312+
for_each = var.cache_policy_id == null ? [true] : []
313+
content {
314+
query_string = var.forward_query_string
315+
query_string_cache_keys = var.query_string_cache_keys
316+
headers = var.forward_header_values
313317

314-
cookies {
315-
forward = var.forward_cookies
318+
cookies {
319+
forward = var.forward_cookies
320+
}
316321
}
317322
}
318323

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ variable "cached_methods" {
197197
description = "List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD)"
198198
}
199199

200+
variable "cache_policy_id" {
201+
type = string
202+
default = null
203+
description = "The unique identifier of the cache policy that is attached to the default cache behavior"
204+
}
205+
200206
variable "default_ttl" {
201207
type = number
202208
default = 60

0 commit comments

Comments
 (0)