|
| 1 | +resource "aws_wafv2_web_acl" "this" { |
| 2 | + name = "${var.project_name}-web-acl" |
| 3 | + scope = "REGIONAL" |
| 4 | + |
| 5 | + default_action { |
| 6 | + allow {} |
| 7 | + } |
| 8 | + |
| 9 | + # Rate-based Rule (HTTP Flood) |
| 10 | + rule { |
| 11 | + name = "Rate-Limit-Rule" |
| 12 | + priority = 1 |
| 13 | + action { |
| 14 | + block {} |
| 15 | + } |
| 16 | + statement { |
| 17 | + rate_based_statement { |
| 18 | + limit = var.request_threshold |
| 19 | + aggregate_key_type = "IP" |
| 20 | + } |
| 21 | + } |
| 22 | + visibility_config { |
| 23 | + cloudwatch_metrics_enabled = true |
| 24 | + metric_name = "rate-limit-rule" |
| 25 | + sampled_requests_enabled = true |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + # AWS Managed Core Rule Set |
| 30 | + rule { |
| 31 | + name = "AWS-Managed-Core-Rule-Set" |
| 32 | + priority = 10 |
| 33 | + override_action { |
| 34 | + none {} |
| 35 | + } |
| 36 | + statement { |
| 37 | + managed_rule_group_statement { |
| 38 | + vendor_name = "AWS" |
| 39 | + name = "AWSManagedRulesCommonRuleSet" |
| 40 | + } |
| 41 | + } |
| 42 | + visibility_config { |
| 43 | + cloudwatch_metrics_enabled = true |
| 44 | + metric_name = "aws-managed-common" |
| 45 | + sampled_requests_enabled = true |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + # Scanners & Probes Protection |
| 50 | + rule { |
| 51 | + name = "AWS-Managed-Known-Bad-Inputs-Rule-Set" |
| 52 | + priority = 20 |
| 53 | + override_action { |
| 54 | + none {} |
| 55 | + } |
| 56 | + statement { |
| 57 | + managed_rule_group_statement { |
| 58 | + vendor_name = "AWS" |
| 59 | + name = "AWSManagedRulesKnownBadInputsRuleSet" |
| 60 | + } |
| 61 | + } |
| 62 | + visibility_config { |
| 63 | + cloudwatch_metrics_enabled = true |
| 64 | + metric_name = "aws-managed-bad-inputs" |
| 65 | + sampled_requests_enabled = true |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + # Reputation Lists Protection |
| 70 | + rule { |
| 71 | + name = "AWS-Managed-Amazon-IP-Reputation-List" |
| 72 | + priority = 30 |
| 73 | + override_action { |
| 74 | + none {} |
| 75 | + } |
| 76 | + statement { |
| 77 | + managed_rule_group_statement { |
| 78 | + vendor_name = "AWS" |
| 79 | + name = "AWSManagedRulesAmazonIpReputationList" |
| 80 | + } |
| 81 | + } |
| 82 | + visibility_config { |
| 83 | + cloudwatch_metrics_enabled = true |
| 84 | + metric_name = "aws-managed-ip-rep" |
| 85 | + sampled_requests_enabled = true |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + # Bad Bot Protection |
| 90 | + rule { |
| 91 | + name = "AWS-Managed-Bot-Control-Rule-Set" |
| 92 | + priority = 40 |
| 93 | + override_action { |
| 94 | + none {} |
| 95 | + } |
| 96 | + statement { |
| 97 | + managed_rule_group_statement { |
| 98 | + vendor_name = "AWS" |
| 99 | + name = "AWSManagedRulesBotControlRuleSet" |
| 100 | + } |
| 101 | + } |
| 102 | + visibility_config { |
| 103 | + cloudwatch_metrics_enabled = true |
| 104 | + metric_name = "aws-managed-bot-control" |
| 105 | + sampled_requests_enabled = true |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + # Anonymous IP list |
| 110 | + rule { |
| 111 | + name = "AWS-Managed-Anonymous-IP-List" |
| 112 | + priority = 50 |
| 113 | + override_action { |
| 114 | + none {} |
| 115 | + } |
| 116 | + statement { |
| 117 | + managed_rule_group_statement { |
| 118 | + vendor_name = "AWS" |
| 119 | + name = "AWSManagedRulesAnonymousIpList" |
| 120 | + } |
| 121 | + } |
| 122 | + visibility_config { |
| 123 | + cloudwatch_metrics_enabled = true |
| 124 | + metric_name = "aws-managed-anonymous-ip" |
| 125 | + sampled_requests_enabled = true |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + # SQL database |
| 130 | + rule { |
| 131 | + name = "AWS-Managed-SQLi-Rule-Set" |
| 132 | + priority = 60 |
| 133 | + override_action { |
| 134 | + none {} |
| 135 | + } |
| 136 | + statement { |
| 137 | + managed_rule_group_statement { |
| 138 | + vendor_name = "AWS" |
| 139 | + name = "AWSManagedRulesSQLiRuleSet" |
| 140 | + } |
| 141 | + } |
| 142 | + visibility_config { |
| 143 | + cloudwatch_metrics_enabled = true |
| 144 | + metric_name = "aws-managed-sql-db" |
| 145 | + sampled_requests_enabled = true |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + visibility_config { |
| 150 | + cloudwatch_metrics_enabled = true |
| 151 | + metric_name = "${var.project_name}-web-acl" |
| 152 | + sampled_requests_enabled = true |
| 153 | + } |
| 154 | + |
| 155 | + tags = var.tags |
| 156 | +} |
0 commit comments