File tree Expand file tree Collapse file tree 7 files changed +43
-16
lines changed
Expand file tree Collapse file tree 7 files changed +43
-16
lines changed Original file line number Diff line number Diff line change 1+ module "cloudfront_firewall_waf_v2" {
2+ source = " ./modules/firewall_waf_v2"
3+ cloudfront_acl = true
4+
5+ environment = var. environment
6+ owner = var. owner
7+ count = local. is_sandbox ? 0 : 1
8+ providers = {aws = aws.us_east_1}
9+ }
10+
111module "cloudfront-distribution-lg" {
2- source = " ./modules/cloudfront/ "
12+ source = " ./modules/cloudfront"
313 bucket_domain_name = " ${ terraform . workspace } -${ var . lloyd_george_bucket_name } .s3.eu-west-2.amazonaws.com"
414 bucket_id = module. ndr-lloyd-george-store . bucket_id
515 qualifed_arn = module. edge-presign-lambda . qualified_arn
616 depends_on = [module . edge-presign-lambda . qualified_arn , module . ndr-lloyd-george-store . bucket_id , module . ndr-lloyd-george-store . bucket_domain_name ]
7- }
17+ web_acl_id = try (module. cloudfront_firewall_waf_v2 [0 ]. arn , " " )
18+ }
Original file line number Diff line number Diff line change 11module "firewall_waf_v2" {
22 source = " ./modules/firewall_waf_v2"
3+ cloudfront_acl = false
34
45 environment = var. environment
56 owner = var. owner
6- count = (terraform. workspace == " ndra" ||
7- terraform. workspace == " ndrb" ||
8- terraform. workspace == " ndrc" ||
9- terraform. workspace == " ndrd" ) ? 0 : 1
7+ count = local. is_sandbox ? 0 : 1
108}
119
1210resource "aws_wafv2_web_acl_association" "web_acl_association" {
@@ -21,4 +19,5 @@ resource "aws_wafv2_web_acl_association" "web_acl_association" {
2119 module . ndr-ecs-fargate-app ,
2220 module . firewall_waf_v2 [0 ]
2321 ]
24- }
22+ }
23+
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ resource "aws_cloudfront_distribution" "distribution" {
3636 locations = [" GB" ]
3737 }
3838 }
39+ web_acl_id = var. web_acl_id
3940}
4041
4142resource "aws_cloudfront_origin_request_policy" "viewer_policy" {
@@ -90,4 +91,5 @@ resource "aws_cloudfront_cache_policy" "nocache" {
9091 query_string_behavior = " none"
9192 }
9293 }
93- }
94+ }
95+
Original file line number Diff line number Diff line change @@ -11,4 +11,10 @@ variable "bucket_id" {
1111variable "qualifed_arn" {
1212 type = string
1313 description = " Lambda@Edge function association"
14- }
14+ }
15+
16+ variable "web_acl_id" {
17+ type = string
18+ description = " Web ACL to associate this Cloudfront distribution with"
19+ }
20+
Original file line number Diff line number Diff line change 11resource "aws_wafv2_web_acl" "waf_v2_acl" {
2- name = " ${ terraform . workspace } -fw-waf-v2"
2+ name = " ${ terraform . workspace } - ${ var . cloudfront_acl ? " cloudwatch " : " " } -fw-waf-v2"
33 description = " A WAF to secure the Repo application."
4- scope = " REGIONAL"
4+ scope = var . cloudfront_acl ? " CLOUDFRONT " : " REGIONAL"
55
66 default_action {
77 allow {}
@@ -50,6 +50,9 @@ resource "aws_wafv2_web_acl" "waf_v2_acl" {
5050 for_each = rule. value [" excluded_rules" ]
5151 content {
5252 name = excluded_rule. value
53+ action_to_use {
54+ allow {}
55+ }
5356 }
5457 }
5558
@@ -97,4 +100,5 @@ resource "aws_wafv2_web_acl" "waf_v2_acl" {
97100 Environment = var.environment
98101 Workspace = terraform.workspace
99102 }
100- }
103+ }
104+
Original file line number Diff line number Diff line change 11resource "aws_wafv2_regex_pattern_set" "large_body_uri" {
22 name = " ${ terraform . workspace } -fw-waf-body-size"
33 description = " A set of regex to allow specific pages to bypass the large body check"
4- scope = " REGIONAL"
4+ scope = var . cloudfront_acl ? " CLOUDFRONT " : " REGIONAL"
55
66 # Allow pages involving images
77 regular_expression {
@@ -24,7 +24,7 @@ resource "aws_wafv2_regex_pattern_set" "large_body_uri" {
2424resource "aws_wafv2_regex_pattern_set" "xss_body_uri" {
2525 name = " ${ terraform . workspace } -fw-waf-body-xss"
2626 description = " A regex to allow specific pages to bypass XSS checks on body"
27- scope = " REGIONAL"
27+ scope = var . cloudfront_acl ? " CLOUDFRONT " : " REGIONAL"
2828
2929 # Allow pages involving images
3030 regular_expression {
@@ -42,7 +42,7 @@ resource "aws_wafv2_regex_pattern_set" "xss_body_uri" {
4242resource "aws_wafv2_regex_pattern_set" "exclude_cms_uri" {
4343 name = " ${ terraform . workspace } -fw-waf-cms-exclude"
4444 description = " A regex to allow CMS calls to bypass firewalls"
45- scope = " REGIONAL"
45+ scope = var . cloudfront_acl ? " CLOUDFRONT " : " REGIONAL"
4646
4747 # Allow pages involving images
4848 regular_expression {
Original file line number Diff line number Diff line change @@ -4,4 +4,9 @@ variable "environment" {
44
55variable "owner" {
66 type = string
7- }
7+ }
8+
9+ variable "cloudfront_acl" {
10+ type = bool
11+ }
12+
You can’t perform that action at this time.
0 commit comments