Skip to content

Commit 56c22f9

Browse files
fix: Upgrade to AWS Provider v5 and add variable ip rate limit endpoint (#4)
* fix: Update aws_wafv2_web_acl rule definitions, remove deprecated code * fix: The API endpoint for the rate limit is now a variable. * terraform-docs: automated action * fix: Generate docs * fix: Increme minimum AWS Provider Version * terraform-docs: automated action --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 12d974d commit 56c22f9

File tree

4 files changed

+20
-114
lines changed

4 files changed

+20
-114
lines changed

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ User Pool.
5353
| Name | Description | Type | Default | Required |
5454
|------|-------------|------|---------|:--------:|
5555
| <a name="input_name"></a> [name](#input\_name) | Friendly name of the rule. | `string` | n/a | yes |
56+
| <a name="input_rate_limit_positional_constraint"></a> [rate\_limit\_positional\_constraint](#input\_rate\_limit\_positional\_constraint) | The area within the portion of a web request that you want AWS WAF to search for rate limiting headers. Valid values: EXACTLY, STARTS\_WITH, ENDS\_WITH, CONTAINS, and CONTAINS\_WORD. The default value is EXACTLY. | `string` | `"STARTS_WITH"` | no |
57+
| <a name="input_rate_limit_search_string"></a> [rate\_limit\_search\_string](#input\_rate\_limit\_search\_string) | String value that you want AWS WAF to search for. AWS WAF searches only in the part of web requests that you designate for inspection in field\_to\_match. The maximum length of the value is 50 bytes. | `string` | `"/api"` | no |
5658
| <a name="input_resource_arn"></a> [resource\_arn](#input\_resource\_arn) | The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool. | `string` | n/a | yes |
5759
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to add to the Resources. | `map(any)` | `{}` | no |
5860

@@ -64,13 +66,13 @@ No outputs.
6466

6567
| Name | Version |
6668
|------|---------|
67-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.4 |
69+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0, < 6.0 |
6870

6971
## Resources
7072

71-
- resource.aws_wafv2_ip_set.ip_blocking (main.tf#399)
73+
- resource.aws_wafv2_ip_set.ip_blocking (main.tf#291)
7274
- resource.aws_wafv2_web_acl.main (main.tf#12)
73-
- resource.aws_wafv2_web_acl_association.main (main.tf#417)
75+
- resource.aws_wafv2_web_acl_association.main (main.tf#309)
7476

7577
# Examples
7678
### Basic Example

Diff for: main.tf

+2-110
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ resource "aws_wafv2_web_acl" "main" {
5959

6060
scope_down_statement {
6161
byte_match_statement {
62-
positional_constraint = "STARTS_WITH"
63-
search_string = "/api/"
62+
positional_constraint = var.rate_limit_positional_constraint
63+
search_string = var.rate_limit_search_string
6464

6565
field_to_match {
6666
uri_path {}
@@ -137,28 +137,6 @@ resource "aws_wafv2_web_acl" "main" {
137137
managed_rule_group_statement {
138138
name = "AWSManagedRulesBotControlRuleSet"
139139
vendor_name = "AWS"
140-
141-
dynamic "excluded_rule" {
142-
for_each = [
143-
"CategoryAdvertising",
144-
"CategoryArchiver",
145-
"CategoryContentFetcher",
146-
"CategoryHttpLibrary",
147-
"CategoryMiscellaneous",
148-
"CategoryMonitoring",
149-
"CategoryScrapingFramework",
150-
"CategorySearchEngine",
151-
"CategorySecurity",
152-
"CategorySeo",
153-
"CategorySocialMedia",
154-
"SignalNonBrowserUserAgent",
155-
"SignalAutomatedBrowser",
156-
"SignalKnownBotDataCenter",
157-
]
158-
content {
159-
name = excluded_rule.value
160-
}
161-
}
162140
}
163141
}
164142

@@ -181,15 +159,6 @@ resource "aws_wafv2_web_acl" "main" {
181159
managed_rule_group_statement {
182160
name = "AWSManagedRulesAmazonIpReputationList"
183161
vendor_name = "AWS"
184-
185-
dynamic "excluded_rule" {
186-
for_each = [
187-
"AWSManagedIPReputationList",
188-
]
189-
content {
190-
name = excluded_rule.value
191-
}
192-
}
193162
}
194163
}
195164

@@ -212,36 +181,6 @@ resource "aws_wafv2_web_acl" "main" {
212181
managed_rule_group_statement {
213182
name = "AWSManagedRulesCommonRuleSet"
214183
vendor_name = "AWS"
215-
216-
dynamic "excluded_rule" {
217-
for_each = [
218-
"CrossSiteScripting_BODY",
219-
"CrossSiteScripting_COOKIE",
220-
"CrossSiteScripting_QUERYARGUMENTS",
221-
"CrossSiteScripting_URIPATH",
222-
"EC2MetaDataSSRF_BODY",
223-
"EC2MetaDataSSRF_COOKIE",
224-
"EC2MetaDataSSRF_QUERYARGUMENTS",
225-
"EC2MetaDataSSRF_URIPATH",
226-
"GenericLFI_BODY",
227-
"GenericLFI_QUERYARGUMENTS",
228-
"GenericLFI_URIPATH",
229-
"GenericRFI_BODY",
230-
"GenericRFI_QUERYARGUMENTS",
231-
"GenericRFI_URIPATH",
232-
"NoUserAgent_HEADER",
233-
"RestrictedExtensions_QUERYARGUMENTS",
234-
"RestrictedExtensions_URIPATH",
235-
"SizeRestrictions_BODY",
236-
"SizeRestrictions_Cookie_HEADER",
237-
"SizeRestrictions_QUERYSTRING",
238-
"SizeRestrictions_URIPATH",
239-
"UserAgent_BadBots_HEADER",
240-
]
241-
content {
242-
name = excluded_rule.value
243-
}
244-
}
245184
}
246185
}
247186

@@ -264,18 +203,6 @@ resource "aws_wafv2_web_acl" "main" {
264203
managed_rule_group_statement {
265204
name = "AWSManagedRulesKnownBadInputsRuleSet"
266205
vendor_name = "AWS"
267-
268-
dynamic "excluded_rule" {
269-
for_each = [
270-
"BadAuthToken_COOKIE_AUTHORIZATION",
271-
"ExploitablePaths_URIPATH",
272-
"Host_localhost_HEADER",
273-
"PROPFIND_METHOD",
274-
]
275-
content {
276-
name = excluded_rule.value
277-
}
278-
}
279206
}
280207
}
281208

@@ -298,17 +225,6 @@ resource "aws_wafv2_web_acl" "main" {
298225
managed_rule_group_statement {
299226
name = "AWSManagedRulesLinuxRuleSet"
300227
vendor_name = "AWS"
301-
302-
dynamic "excluded_rule" {
303-
for_each = [
304-
"LFI_BODY",
305-
"LFI_QUERYARGUMENTS",
306-
"LFI_URIPATH",
307-
]
308-
content {
309-
name = excluded_rule.value
310-
}
311-
}
312228
}
313229
}
314230

@@ -331,16 +247,6 @@ resource "aws_wafv2_web_acl" "main" {
331247
managed_rule_group_statement {
332248
name = "AWSManagedRulesPHPRuleSet"
333249
vendor_name = "AWS"
334-
335-
dynamic "excluded_rule" {
336-
for_each = [
337-
"PHPHighRiskMethodsVariables_BODY",
338-
"PHPHighRiskMethodsVariables_QUERYARGUMENTS",
339-
]
340-
content {
341-
name = excluded_rule.value
342-
}
343-
}
344250
}
345251
}
346252

@@ -363,20 +269,6 @@ resource "aws_wafv2_web_acl" "main" {
363269
managed_rule_group_statement {
364270
name = "AWSManagedRulesSQLiRuleSet"
365271
vendor_name = "AWS"
366-
367-
dynamic "excluded_rule" {
368-
for_each = [
369-
"SQLiExtendedPatterns_QUERYARGUMENTS",
370-
"SQLi_BODY",
371-
"SQLi_COOKIE",
372-
"SQLi_QUERYARGUMENTS",
373-
"SQLi_QUERYSTRING_COUNT",
374-
"SQLi_URIPATH",
375-
]
376-
content {
377-
name = excluded_rule.value
378-
}
379-
}
380272
}
381273
}
382274

Diff for: variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ variable "name" {
1111
type = string
1212
}
1313

14+
variable "rate_limit_positional_constraint" {
15+
description = "The area within the portion of a web request that you want AWS WAF to search for rate limiting headers. Valid values: EXACTLY, STARTS_WITH, ENDS_WITH, CONTAINS, and CONTAINS_WORD. The default value is EXACTLY."
16+
default = "STARTS_WITH"
17+
type = string
18+
}
19+
20+
variable "rate_limit_search_string" {
21+
description = "String value that you want AWS WAF to search for. AWS WAF searches only in the part of web requests that you designate for inspection in field_to_match. The maximum length of the value is 50 bytes."
22+
default = "/api"
23+
type = string
24+
}
25+
1426
variable "resource_arn" {
1527
description = "The Amazon Resource Name (ARN) of the resource to associate with the web ACL. This must be an ARN of an Application Load Balancer, an Amazon API Gateway stage, or an Amazon Cognito User Pool."
1628
type = string

Diff for: versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.4"
7+
version = ">= 5.0, < 6.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)