Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for blacklisting paths for caching #63

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Available targets:
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no |
| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list(string) | `<list>` | no |
| caching_blacklist | Paths of objects that should never be cached for any HTTP methods | set(string) | `<list>` | no |
| comment | Comment for the origin access identity | string | `Managed by Terraform` | no |
| compress | Compress content for web requests that include Accept-Encoding: gzip in the request header | bool | `false` | no |
| cors_allowed_headers | List of allowed headers for S3 bucket | list(string) | `<list>` | no |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
| bucket_domain_format | Format of bucket domain name | string | `%s.s3.amazonaws.com` | no |
| cached_methods | List of cached methods (e.g. GET, PUT, POST, DELETE, HEAD) | list(string) | `<list>` | no |
| caching_blacklist | Paths of objects that should never be cached for any HTTP methods | set(string) | `<list>` | no |
| comment | Comment for the origin access identity | string | `Managed by Terraform` | no |
| compress | Compress content for web requests that include Accept-Encoding: gzip in the request header | bool | `false` | no |
| cors_allowed_headers | List of allowed headers for S3 bucket | list(string) | `<list>` | no |
Expand Down
26 changes: 26 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,32 @@ resource "aws_cloudfront_distribution" "default" {
}
}

dynamic "ordered_cache_behavior" {
for_each = var.caching_blacklist
content {
path_pattern = ordered_cache_behavior.value
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD", "OPTIONS"]
target_origin_id = module.distribution_label.id
compress = var.compress
trusted_signers = var.trusted_signers

forwarded_values {
query_string = var.forward_query_string
headers = var.forward_header_values

cookies {
forward = var.forward_cookies
}
}

viewer_protocol_policy = var.viewer_protocol_policy
default_ttl = 0
min_ttl = 0
max_ttl = 0
}
}

restrictions {
geo_restriction {
restriction_type = var.geo_restriction_type
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ variable "viewer_protocol_policy" {
default = "redirect-to-https"
}

variable "caching_blacklist" {
type = set(string)
default = []
description = "Paths of objects that should never be cached for any HTTP methods"
}

variable "allowed_methods" {
type = list(string)
default = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
Expand Down