Skip to content

Commit ad653b6

Browse files
committed
test: adding RegexMatchStatemnet tests
Also adding an example for RegexMatchStatements. Both were previously missing.
1 parent 381c39b commit ad653b6

File tree

6 files changed

+732
-0
lines changed

6 files changed

+732
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Usage
2+
3+
To run this example you need to execute:
4+
5+
```bash
6+
$ terraform init
7+
$ terraform plan
8+
$ terraform apply
9+
```
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
provider "aws" {
2+
region = "ap-northeast-2"
3+
}
4+
5+
module "wafv2" {
6+
source = "../..//"
7+
8+
enabled_web_acl_association = true
9+
resource_arn = []
10+
11+
enabled_logging_configuration = false
12+
13+
name = "WebACL01"
14+
scope = "REGIONAL"
15+
default_action = "allow"
16+
rule = [
17+
{
18+
name = "APIVersionRegexRule"
19+
priority = 10
20+
action = "block"
21+
regex_match_statement = {
22+
field_to_match = {
23+
uri_path = {}
24+
}
25+
regex_string = "^/api/v[0-9]+/.*"
26+
text_transformation = [
27+
{
28+
priority = 0
29+
type = "LOWERCASE"
30+
}
31+
]
32+
}
33+
visibility_config = {
34+
cloudwatch_metrics_enabled = true
35+
metric_name = "APIVersionRegexRule"
36+
sampled_requests_enabled = true
37+
}
38+
},
39+
{
40+
name = "JWTTokenRegexRule"
41+
priority = 20
42+
action = "allow"
43+
regex_match_statement = {
44+
field_to_match = {
45+
single_header = {
46+
name = "authorization"
47+
}
48+
}
49+
regex_string = "^Bearer [A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]+$"
50+
text_transformation = [
51+
{
52+
priority = 0
53+
type = "NONE"
54+
}
55+
]
56+
}
57+
visibility_config = {
58+
cloudwatch_metrics_enabled = true
59+
metric_name = "JWTTokenRegexRule"
60+
sampled_requests_enabled = true
61+
}
62+
},
63+
{
64+
name = "SQLInjectionRegexRule"
65+
priority = 30
66+
action = "block"
67+
regex_match_statement = {
68+
field_to_match = {
69+
query_string = {}
70+
}
71+
regex_string = ".*(select|union|insert|delete|drop).*"
72+
text_transformation = [
73+
{
74+
priority = 0
75+
type = "LOWERCASE"
76+
},
77+
{
78+
priority = 1
79+
type = "URL_DECODE"
80+
}
81+
]
82+
}
83+
visibility_config = {
84+
cloudwatch_metrics_enabled = true
85+
metric_name = "SQLInjectionRegexRule"
86+
sampled_requests_enabled = true
87+
}
88+
},
89+
{
90+
name = "EmailValidationRegexRule"
91+
priority = 40
92+
action = "allow"
93+
regex_match_statement = {
94+
field_to_match = {
95+
single_query_argument = {
96+
name = "email"
97+
}
98+
}
99+
regex_string = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
100+
text_transformation = [
101+
{
102+
priority = 0
103+
type = "LOWERCASE"
104+
}
105+
]
106+
}
107+
visibility_config = {
108+
cloudwatch_metrics_enabled = true
109+
metric_name = "EmailValidationRegexRule"
110+
sampled_requests_enabled = true
111+
}
112+
}
113+
]
114+
visibility_config = {
115+
cloudwatch_metrics_enabled = false
116+
metric_name = "cloudwatch_metric_name"
117+
sampled_requests_enabled = false
118+
}
119+
tags = {
120+
Team = "Security"
121+
Owner = "Security"
122+
}
123+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "web_acl_arn" {
2+
description = "The ARN of the WAFv2 Web ACL"
3+
value = module.wafv2.aws_wafv2_arn
4+
}
5+
6+
output "web_acl_id" {
7+
description = "The ID of the WAFv2 Web ACL"
8+
value = module.wafv2.aws_wafv2_id
9+
}
10+
11+
output "web_acl_capacity" {
12+
description = "The capacity of the WAFv2 Web ACL"
13+
value = module.wafv2.aws_wafv2_capacity
14+
}
15+
16+
output "web_acl_rules" {
17+
description = "The rules configured in the WAFv2 Web ACL"
18+
value = module.wafv2.aws_wafv2_rule
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No variables needed for this example
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.32"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)