Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Regex Match Statements #63

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions .github/workflows/test.yaml.disabled

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
Expand All @@ -18,7 +18,7 @@ repos:
args: ['--allow-missing-credentials']
- id: trailing-whitespace
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.72.1
rev: v1.77.0
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Supported WAF v2 components:
- Logical Statements (AND, OR, NOT)
- Size constraint statements
- Label Match statements
- Regex Match statements
- Regex Pattern Match statements
- Custom responses

Expand Down Expand Up @@ -217,6 +218,28 @@ module "waf" {
}
}
},
### Regex Match Rule example
{
name = "RegexMatchRule-9"
priority = "9"
action = "allow"
visibility_config = {
cloudwatch_metrics_enabled = false
metric_name = "RegexMatchRule-metric"
sampled_requests_enabled = false
}
byte_match_statement = {
field_to_match = {
uri_path = "{}"
}
regex_string = "/foo/"
priority = 0
type = "NONE"
}
},
### Size constraint Rule example
# Refer to https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl#size-constraint-statement
# for all of the options available.
Expand Down
8 changes: 8 additions & 0 deletions examples/core/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-and-or-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-bytematch-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-custom-response-code/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-custom-response/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-geo-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-ip-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-labelmatch-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-logging-configuration/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
8 changes: 8 additions & 0 deletions examples/wafv2-regex-pattern-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
57 changes: 57 additions & 0 deletions examples/wafv2-regexmatch-rules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
#####
# Web Application Firewall configuration
#####
module "waf" {
source = "../.."

name_prefix = var.name_prefix

allow_default_action = true

scope = "REGIONAL"

create_alb_association = false

visibility_config = {
cloudwatch_metrics_enabled = false
metric_name = "${var.name_prefix}-waf-setup-waf-main-metrics"
sampled_requests_enabled = false
}

rules = [
{
name = "block-some-path"
priority = "1"
action = "block"

regex_match_statement = {
field_to_match = {
uri_path = "{}"
}
regex_string = "^/(path1|path2)/"
priority = 0
type = "NONE"
}

visibility_config = {
cloudwatch_metrics_enabled = false
sampled_requests_enabled = false
}
}
]

tags = {
"Environment" = "test"
}
}
24 changes: 24 additions & 0 deletions examples/wafv2-regexmatch-rules/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
output "web_acl_name" {
description = "The name of the WAFv2 WebACL."
value = module.waf.web_acl_name
}

output "web_acl_arn" {
description = "The ARN of the WAFv2 WebACL."
value = module.waf.web_acl_arn
}

output "web_acl_capacity" {
description = "The web ACL capacity units (WCUs) currently being used by this web ACL."
value = module.waf.web_acl_capacity
}

output "web_acl_visibility_config_name" {
description = "The web ACL visibility config name"
value = module.waf.web_acl_visibility_config_name
}

output "web_acl_rule_names" {
description = "List of created rule names"
value = module.waf.web_acl_rule_names
}
5 changes: 5 additions & 0 deletions examples/wafv2-regexmatch-rules/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "name_prefix" {
description = "A prefix used for naming resources."
type = string
default = "example"
}
8 changes: 8 additions & 0 deletions examples/wafv2-sizeconstraint-rules/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 4.0.0"
}
}

provider "aws" {
region = "eu-west-1"
}
Expand Down
Loading