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-
271resource "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