Skip to content

Commit

Permalink
feat: Allow WAF to be put into passive mode. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes authored Oct 18, 2024
1 parent 2fb8635 commit d8650ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Bump version and create changelog
id: bump
uses: commitizen-tools/commitizen-action@master
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ these rules are spaced out to allow for custom rules to be inserted between.
| [ip_set_rules] | The environment for the project. | `map(object)` | `"dev"` | no |
| log_group | CloudWatch log group to send WAF logs to. | `list(string)` | `[]` | no |
| origin_domain | Fully qualified domain name for the origin. Defaults to `origin.${subdomain}.${domain}`. | `string` | n/a | no |
| passive | Enable passive mode for the WAF, counting all requests rather than blocking. | `bool` | `false` | no |
| subdomain | Subdomain for the distribution. Defaults to the environment. | `string` | n/a | no |
| tags | Optional tags to be applied to all resources. | `list` | `[]` | no |

Expand Down
43 changes: 38 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ resource "aws_wafv2_web_acl" "waf" {
content {}
}

dynamic "block" {
dynamic "count" {
for_each = rule.value.action == "count" ? [true] : []
content {}
}
Expand All @@ -133,6 +133,7 @@ resource "aws_wafv2_web_acl" "waf" {
}
}

# TODO: Make rate-limiting configurable.
rule {
name = "AWS-RateBasedRule-IP-300"
priority = 100
Expand Down Expand Up @@ -161,7 +162,15 @@ resource "aws_wafv2_web_acl" "waf" {
priority = 200

override_action {
none {}
dynamic "none" {
for_each = var.passive ? [] : [true]
content { }
}

dynamic "count" {
for_each = var.passive ? [true] : []
content { }
}
}

statement {
Expand All @@ -183,7 +192,15 @@ resource "aws_wafv2_web_acl" "waf" {
priority = 300

override_action {
none {}
dynamic "none" {
for_each = var.passive ? [] : [true]
content { }
}

dynamic "count" {
for_each = var.passive ? [true] : []
content { }
}
}

statement {
Expand All @@ -205,7 +222,15 @@ resource "aws_wafv2_web_acl" "waf" {
priority = 400

override_action {
none {}
dynamic "none" {
for_each = var.passive ? [] : [true]
content { }
}

dynamic "count" {
for_each = var.passive ? [true] : []
content { }
}
}

statement {
Expand All @@ -227,7 +252,15 @@ resource "aws_wafv2_web_acl" "waf" {
priority = 500

override_action {
none {}
dynamic "none" {
for_each = var.passive ? [] : [true]
content { }
}

dynamic "count" {
for_each = var.passive ? [true] : []
content { }
}
}

statement {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ variable "origin_domain" {
default = ""
}

variable "passive" {
type = bool
description = "Enable passive mode for the WAF, counting all requests rather than blocking."
default = false
}

variable "project" {
type = string
description = "Project that these resources are supporting."
Expand Down

0 comments on commit d8650ac

Please sign in to comment.