Skip to content

Commit d991e61

Browse files
committed
Document logical statements
1 parent 5ce16d0 commit d991e61

File tree

1 file changed

+145
-4
lines changed

1 file changed

+145
-4
lines changed

website/docs/r/wafv2_web_acl_rule.html.markdown

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,124 @@ With this configuration, when you remove both the `aws_wafv2_web_acl_rule` and `
234234

235235
This prevents the `WAFAssociatedItemException` error.
236236

237+
### Logical AND Statement
238+
239+
Block requests that match multiple conditions (e.g., from a specific country AND containing a specific string):
240+
241+
```terraform
242+
resource "aws_wafv2_web_acl_rule" "block_suspicious" {
243+
name = "block-suspicious"
244+
priority = 1
245+
web_acl_arn = aws_wafv2_web_acl.example.arn
246+
247+
action {
248+
block {}
249+
}
250+
251+
statement {
252+
and_statement {
253+
statement {
254+
geo_match_statement {
255+
country_codes = ["CN"]
256+
}
257+
}
258+
259+
statement {
260+
byte_match_statement {
261+
search_string = "admin"
262+
positional_constraint = "CONTAINS"
263+
264+
field_to_match {
265+
uri_path {}
266+
}
267+
268+
text_transformation {
269+
priority = 0
270+
type = "LOWERCASE"
271+
}
272+
}
273+
}
274+
}
275+
}
276+
277+
visibility_config {
278+
cloudwatch_metrics_enabled = true
279+
metric_name = "block-suspicious"
280+
sampled_requests_enabled = true
281+
}
282+
}
283+
```
284+
285+
### Logical OR Statement
286+
287+
Block requests that match any of multiple conditions:
288+
289+
```terraform
290+
resource "aws_wafv2_web_acl_rule" "block_countries" {
291+
name = "block-countries"
292+
priority = 2
293+
web_acl_arn = aws_wafv2_web_acl.example.arn
294+
295+
action {
296+
block {}
297+
}
298+
299+
statement {
300+
or_statement {
301+
statement {
302+
geo_match_statement {
303+
country_codes = ["CN"]
304+
}
305+
}
306+
307+
statement {
308+
geo_match_statement {
309+
country_codes = ["RU"]
310+
}
311+
}
312+
}
313+
}
314+
315+
visibility_config {
316+
cloudwatch_metrics_enabled = true
317+
metric_name = "block-countries"
318+
sampled_requests_enabled = true
319+
}
320+
}
321+
```
322+
323+
### Logical NOT Statement
324+
325+
Allow requests only from specific countries by negating a geo match:
326+
327+
```terraform
328+
resource "aws_wafv2_web_acl_rule" "allow_only_us" {
329+
name = "allow-only-us"
330+
priority = 3
331+
web_acl_arn = aws_wafv2_web_acl.example.arn
332+
333+
action {
334+
block {}
335+
}
336+
337+
statement {
338+
not_statement {
339+
statement {
340+
geo_match_statement {
341+
country_codes = ["US", "CA"]
342+
}
343+
}
344+
}
345+
}
346+
347+
visibility_config {
348+
cloudwatch_metrics_enabled = true
349+
metric_name = "allow-only-us"
350+
sampled_requests_enabled = true
351+
}
352+
}
353+
```
354+
237355
## Argument Reference
238356

239357
The following arguments are required:
@@ -307,12 +425,15 @@ One of the following action blocks must be specified:
307425

308426
Exactly one of the following statement blocks must be specified:
309427

428+
* `and_statement` - (Optional) Logical AND statement that combines multiple statements. See [And Statement](#and-statement) below.
310429
* `asn_match_statement` - (Optional) Match requests based on Autonomous System Number (ASN). See [ASN Match Statement](#asn-match-statement) below.
311430
* `byte_match_statement` - (Optional) Match requests based on byte patterns. See [Byte Match Statement](#byte-match-statement) below.
312431
* `geo_match_statement` - (Optional) Match requests by geographic location. See [Geo Match Statement](#geo-match-statement) below.
313432
* `ip_set_reference_statement` - (Optional) Reference to an IP set. See [IP Set Reference Statement](#ip-set-reference-statement) below.
314433
* `label_match_statement` - (Optional) Match requests based on labels. See [Label Match Statement](#label-match-statement) below.
315434
* `managed_rule_group_statement` - (Optional) Reference to a managed rule group. See [Managed Rule Group Statement](#managed-rule-group-statement) below.
435+
* `not_statement` - (Optional) Logical NOT statement that negates a single statement. See [Not Statement](#not-statement) below.
436+
* `or_statement` - (Optional) Logical OR statement that combines multiple statements. See [Or Statement](#or-statement) below.
316437
* `rate_based_statement` - (Optional) Rate-based rule to track request rates. See [Rate Based Statement](#rate-based-statement) below.
317438
* `regex_match_statement` - (Optional) Match requests using regex patterns. See [Regex Match Statement](#regex-match-statement) below.
318439
* `regex_pattern_set_reference_statement` - (Optional) Reference to a regex pattern set. See [Regex Pattern Set Reference Statement](#regex-pattern-set-reference-statement) below.
@@ -321,6 +442,26 @@ Exactly one of the following statement blocks must be specified:
321442
* `sqli_match_statement` - (Optional) Match requests that appear to contain SQL injection attacks. See [SQL Injection Match Statement](#sql-injection-match-statement) below.
322443
* `xss_match_statement` - (Optional) Match requests that appear to contain cross-site scripting attacks. See [Cross-Site Scripting Match Statement](#cross-site-scripting-match-statement) below.
323444

445+
~> **NOTE:** Logical statements (`and_statement`, `not_statement`, `or_statement`) can be nested up to 3 levels deep. This matches the nesting limit of the `aws_wafv2_web_acl` resource.
446+
447+
#### And Statement
448+
449+
Combines multiple statements using logical AND. All nested statements must match for the AND statement to match.
450+
451+
* `statement` - (Required) List of statements to combine. At least one statement is required. Each nested statement supports the same statement types listed above.
452+
453+
#### Not Statement
454+
455+
Negates a single statement. The NOT statement matches when the nested statement does not match.
456+
457+
* `statement` - (Required) Single statement to negate. Exactly one statement must be specified.
458+
459+
#### Or Statement
460+
461+
Combines multiple statements using logical OR. At least one nested statement must match for the OR statement to match.
462+
463+
* `statement` - (Required) List of statements to combine. At least one statement is required. Each nested statement supports the same statement types listed above.
464+
324465
#### ASN Match Statement
325466

326467
* `asn_list` - (Required) List of Autonomous System Numbers (ASNs) to match against. ASNs are unique identifiers assigned to large internet networks managed by organizations such as internet service providers, enterprises, universities, or government agencies.
@@ -436,10 +577,6 @@ One of the following override action blocks must be specified when using managed
436577
* `metric_name` - (Optional) Name of the CloudWatch metric. Defaults to the rule name.
437578
* `sampled_requests_enabled` - (Optional) Whether to store sampled requests. Defaults to `true`.
438579

439-
## Attribute Reference
440-
441-
This resource exports no additional attributes.
442-
443580
### Field to Match
444581

445582
Exactly one of the following field to match blocks must be specified:
@@ -521,6 +658,10 @@ Exactly one of the following custom key blocks must be specified:
521658

522659
* `name` - (Required) Name of the rule to exclude from the rule group.
523660

661+
## Attribute Reference
662+
663+
This resource exports no additional attributes.
664+
524665
## Import
525666

526667
In Terraform v1.12.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `identity` attribute. For example:

0 commit comments

Comments
 (0)