Skip to content

Commit a8c96de

Browse files
authored
feat: Replaced custom cache policy with managed policy to disable cache. (FYST-1527) (#18)
1 parent be3fe84 commit a8c96de

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ to match your desired configuration. For example, to create a new distribution
1313

1414
```hcl
1515
module "cloudfront_waf" {
16-
source = "github.com/codeforamerica/tofu-modules-aws-cloudfront-waf?ref=1.4.0"
16+
source = "github.com/codeforamerica/tofu-modules-aws-cloudfront-waf?ref=1.6.0"
1717
1818
project = "my-project"
1919
environment = "dev"

data.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
data "aws_cloudfront_origin_request_policy" "managed_cors" {
1+
data "aws_cloudfront_cache_policy" "policy" {
2+
name = "Managed-CachingDisabled"
3+
}
4+
5+
data "aws_cloudfront_origin_request_policy" "policy" {
26
name = "Managed-${var.request_policy}"
37
}
48

5-
data "aws_cloudfront_response_headers_policy" "managed_cors" {
9+
data "aws_cloudfront_response_headers_policy" "policy" {
610
name = "Managed-SimpleCORS"
711
}
812

main.tf

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
resource "aws_cloudfront_cache_policy" "waf_passthrough" {
2-
name = "${var.project}-${var.environment}-waf-passthrough"
3-
comment = "We don't really care about caching, we just want to pass traffic to the WAF."
4-
default_ttl = 1
5-
max_ttl = 1
6-
min_ttl = 1
7-
8-
parameters_in_cache_key_and_forwarded_to_origin {
9-
enable_accept_encoding_brotli = true
10-
enable_accept_encoding_gzip = true
11-
12-
cookies_config {
13-
cookie_behavior = "all"
14-
}
15-
headers_config {
16-
header_behavior = "whitelist"
17-
headers {
18-
items = ["Host"]
19-
}
20-
}
21-
query_strings_config {
22-
query_string_behavior = "all"
23-
}
24-
}
25-
}
26-
271
resource "aws_cloudfront_distribution" "waf" {
282
enabled = true
293
comment = "Pass traffic through WAF before sending to the origin."
@@ -64,7 +38,6 @@ resource "aws_cloudfront_distribution" "waf" {
6438
}
6539

6640
default_cache_behavior {
67-
cache_policy_id = aws_cloudfront_cache_policy.waf_passthrough.id
6841
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
6942
cached_methods = ["GET", "HEAD"]
7043
target_origin_id = local.origin_domain
@@ -73,8 +46,9 @@ resource "aws_cloudfront_distribution" "waf" {
7346
max_ttl = 0
7447
min_ttl = 0
7548

76-
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.managed_cors.id
77-
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.managed_cors.id
49+
cache_policy_id = data.aws_cloudfront_cache_policy.policy.id
50+
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.policy.id
51+
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.policy.id
7852

7953
viewer_protocol_policy = "redirect-to-https"
8054
}

0 commit comments

Comments
 (0)