File tree Expand file tree Collapse file tree 5 files changed +30
-9
lines changed
Expand file tree Collapse file tree 5 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,15 @@ module "firewall_waf_v2" {
66 count = local. is_sandbox ? 0 : 1
77}
88
9+ module "firewall_waf_v2_api" {
10+ source = " ./modules/firewall_waf_v2"
11+ cloudfront_acl = false
12+ environment = var. environment
13+ owner = var. owner
14+ count = local. is_sandbox ? 0 : 1
15+ api = true
16+ }
17+
918resource "aws_wafv2_web_acl_association" "web_acl_association" {
1019 resource_arn = module. ndr-ecs-fargate-app . load_balancer_arn
1120 web_acl_arn = module. firewall_waf_v2 [0 ]. arn
@@ -18,10 +27,10 @@ resource "aws_wafv2_web_acl_association" "web_acl_association" {
1827
1928resource "aws_wafv2_web_acl_association" "api_gateway" {
2029 resource_arn = aws_api_gateway_stage. ndr_api . arn
21- web_acl_arn = module. firewall_waf_v2 [0 ]. arn
30+ web_acl_arn = module. firewall_waf_v2_api [0 ]. arn
2231 count = local. is_sandbox ? 0 : 1
2332 depends_on = [
2433 aws_api_gateway_stage . ndr_api ,
25- module . firewall_waf_v2 [0 ]
34+ module . firewall_waf_v2_api [0 ]
2635 ]
2736}
Original file line number Diff line number Diff line change 22
33 image_regex = " ^\\ /images(\\ /\\ w+)+\\ /$"
44
5- waf_rules = [
5+ waf_rules_raw = [
66 {
77 name = " AWSCoreRuleSet"
88 managed_rule_name = " AWSManagedRulesCommonRuleSet"
@@ -47,8 +47,14 @@ locals {
4747 }
4848 ]
4949
50+ # Filter out AWSBotControl if var.api is true
51+ waf_rules = [
52+ for rule in local . waf_rules_raw : rule
53+ if ! (var. api && rule. name == " AWSBotControl" )
54+ ]
55+
5056 waf_rules_map = zipmap (
5157 range (0 , length (local. waf_rules )),
5258 local. waf_rules
5359 )
54- }
60+ }
Original file line number Diff line number Diff line change 11resource "aws_wafv2_web_acl" "waf_v2_acl" {
2- name = " ${ terraform . workspace } - ${ var . cloudfront_acl ? " cloudfront" : " " } -fw-waf-v2"
2+ name = " ${ terraform . workspace } ${ var . api ? " -api " : var . cloudfront_acl ? " - cloudfront" : " " } -fw-waf-v2"
33 description = " A WAF to secure the Repo application."
44 scope = var. cloudfront_acl ? " CLOUDFRONT" : " REGIONAL"
55
Original file line number Diff line number Diff line change 11resource "aws_wafv2_regex_pattern_set" "large_body_uri" {
2- name = " ${ terraform . workspace } -fw-waf-body-size"
2+ name = " ${ terraform . workspace } -fw-waf-body-size${ var . api ? " -api " : " " } "
33 description = " A set of regex to allow specific pages to bypass the large body check"
44 scope = var. cloudfront_acl ? " CLOUDFRONT" : " REGIONAL"
55
@@ -22,7 +22,7 @@ resource "aws_wafv2_regex_pattern_set" "large_body_uri" {
2222}
2323
2424resource "aws_wafv2_regex_pattern_set" "xss_body_uri" {
25- name = " ${ terraform . workspace } -fw-waf-body-xss"
25+ name = " ${ terraform . workspace } -fw-waf-body-xss${ var . api ? " -api " : " " } "
2626 description = " A regex to allow specific pages to bypass XSS checks on body"
2727 scope = var. cloudfront_acl ? " CLOUDFRONT" : " REGIONAL"
2828
@@ -40,7 +40,7 @@ resource "aws_wafv2_regex_pattern_set" "xss_body_uri" {
4040}
4141
4242resource "aws_wafv2_regex_pattern_set" "exclude_cms_uri" {
43- name = " ${ terraform . workspace } -fw-waf-cms-exclude"
43+ name = " ${ terraform . workspace } -fw-waf-cms-exclude${ var . api ? " -api " : " " } "
4444 description = " A regex to allow CMS calls to bypass firewalls"
4545 scope = var. cloudfront_acl ? " CLOUDFRONT" : " REGIONAL"
4646
@@ -55,4 +55,4 @@ resource "aws_wafv2_regex_pattern_set" "exclude_cms_uri" {
5555 Environment = var.environment
5656 Workspace = terraform.workspace
5757 }
58- }
58+ }
Original file line number Diff line number Diff line change @@ -10,3 +10,9 @@ variable "cloudfront_acl" {
1010 type = bool
1111}
1212
13+ variable "api" {
14+ type = bool
15+ description = " True if using the firewall for an api - removes AWSBotControl"
16+ default = false
17+ }
18+
You can’t perform that action at this time.
0 commit comments