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

Support captcha action in wafv2 rule group #28435

Merged
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
3 changes: 3 additions & 0 deletions .changelog/28435.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_wafv2_rule_group: Add `rule.action.captcha` argument
```
7 changes: 4 additions & 3 deletions internal/service/wafv2/rule_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ func ResourceRuleGroup() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allow": allowConfigSchema(),
"block": blockConfigSchema(),
"count": countConfigSchema(),
"allow": allowConfigSchema(),
"block": blockConfigSchema(),
"count": countConfigSchema(),
"captcha": captchaConfigSchema(),
},
},
},
Expand Down
36 changes: 25 additions & 11 deletions internal/service/wafv2/rule_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestAccWAFV2RuleGroup_updateRule(t *testing.T) {
"action.0.allow.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "1",
"action.0.captcha.#": "0",
"statement.#": "1",
"statement.0.geo_match_statement.#": "1",
"statement.0.geo_match_statement.0.country_codes.#": "2",
Expand Down Expand Up @@ -149,12 +150,13 @@ func TestAccWAFV2RuleGroup_updateRuleProperties(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "visibility_config.0.sampled_requests_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule.*", map[string]string{
"name": "rule-1",
"priority": "1",
"action.#": "1",
"action.0.allow.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "1",
"name": "rule-1",
"priority": "1",
"action.#": "1",
"action.0.allow.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "1",
"action.0.captcha.#": "0",
"visibility_config.0.cloudwatch_metrics_enabled": "false",
"visibility_config.0.metric_name": "friendly-rule-metric-name",
"visibility_config.0.sampled_requests_enabled": "false",
Expand Down Expand Up @@ -187,6 +189,7 @@ func TestAccWAFV2RuleGroup_updateRuleProperties(t *testing.T) {
"action.0.allow.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "1",
"action.0.captcha.#": "0",
"visibility_config.#": "1",
"visibility_config.0.cloudwatch_metrics_enabled": "false",
"visibility_config.0.metric_name": "rule-1",
Expand All @@ -202,6 +205,7 @@ func TestAccWAFV2RuleGroup_updateRuleProperties(t *testing.T) {
"action.0.allow.#": "0",
"action.0.block.#": "1",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
"visibility_config.#": "1",
"visibility_config.0.cloudwatch_metrics_enabled": "false",
"visibility_config.0.metric_name": ruleName2,
Expand Down Expand Up @@ -247,6 +251,7 @@ func TestAccWAFV2RuleGroup_updateRuleProperties(t *testing.T) {
"action.0.allow.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "1",
"action.0.captcha.#": "0",
"visibility_config.#": "1",
"visibility_config.0.cloudwatch_metrics_enabled": "false",
"visibility_config.0.metric_name": "rule-1",
Expand All @@ -262,6 +267,7 @@ func TestAccWAFV2RuleGroup_updateRuleProperties(t *testing.T) {
"action.0.allow.#": "0",
"action.0.block.#": "1",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
"visibility_config.#": "1",
"visibility_config.0.cloudwatch_metrics_enabled": "false",
"visibility_config.0.metric_name": "updated",
Expand Down Expand Up @@ -1398,6 +1404,7 @@ func TestAccWAFV2RuleGroup_ruleAction(t *testing.T) {
"action.0.allow.0.custom_request_handling.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand All @@ -1418,6 +1425,7 @@ func TestAccWAFV2RuleGroup_ruleAction(t *testing.T) {
"action.0.block.#": "1",
"action.0.block.0.custom_response.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand All @@ -1438,6 +1446,7 @@ func TestAccWAFV2RuleGroup_ruleAction(t *testing.T) {
"action.0.block.#": "0",
"action.0.count.#": "1",
"action.0.count.0.custom_request_handling.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand Down Expand Up @@ -1482,8 +1491,9 @@ func TestAccWAFV2RuleGroup_RuleAction_customRequestHandling(t *testing.T) {
"action.0.allow.0.custom_request_handling.0.insert_header.0.value": "test-val1",
"action.0.allow.0.custom_request_handling.0.insert_header.1.name": "x-hdr2",
"action.0.allow.0.custom_request_handling.0.insert_header.1.value": "test-val2",
"action.0.block.#": "0",
"action.0.count.#": "0",
"action.0.block.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand All @@ -1509,6 +1519,7 @@ func TestAccWAFV2RuleGroup_RuleAction_customRequestHandling(t *testing.T) {
"action.0.count.0.custom_request_handling.0.insert_header.0.value": "test-val1",
"action.0.count.0.custom_request_handling.0.insert_header.1.name": "x-hdr2",
"action.0.count.0.custom_request_handling.0.insert_header.1.value": "test-val2",
"action.0.captcha.#": "0",
}),
),
},
Expand Down Expand Up @@ -1555,7 +1566,8 @@ func TestAccWAFV2RuleGroup_RuleAction_customResponse(t *testing.T) {
"action.0.block.0.custom_response.0.response_header.0.value": "test-val1",
"action.0.block.0.custom_response.0.response_header.1.name": "x-hdr2",
"action.0.block.0.custom_response.0.response_header.1.value": "test-val2",
"action.0.count.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand Down Expand Up @@ -1587,7 +1599,8 @@ func TestAccWAFV2RuleGroup_RuleAction_customResponse(t *testing.T) {
"action.0.block.0.custom_response.#": "1",
"action.0.block.0.custom_response.0.response_code": "429",
"action.0.block.0.custom_response.0.custom_response_body_key": "test_body_1",
"action.0.count.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand Down Expand Up @@ -1620,7 +1633,8 @@ func TestAccWAFV2RuleGroup_RuleAction_customResponse(t *testing.T) {
"action.0.block.0.custom_response.#": "1",
"action.0.block.0.custom_response.0.response_code": "429",
"action.0.block.0.custom_response.0.custom_response_body_key": "test_body_2",
"action.0.count.#": "0",
"action.0.count.#": "0",
"action.0.captcha.#": "0",
}),
),
},
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/wafv2_rule_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ The `action` block supports the following arguments:

* `allow` - (Optional) Instructs AWS WAF to allow the web request. See [Allow](#action) below for details.
* `block` - (Optional) Instructs AWS WAF to block the web request. See [Block](#block) below for details.
* `captcha` - (Optional) Instructs AWS WAF to run a `CAPTCHA` check against the web request. See [Captcha](#captcha) below for details.
* `count` - (Optional) Instructs AWS WAF to count the web request and allow it. See [Count](#count) below for details.

### Allow
Expand All @@ -354,6 +355,12 @@ The `block` block supports the following arguments:

* `custom_response` - (Optional) Defines a custom response for the web request. See [Custom Response](#custom-response) below for details.

### Captcha

The `captcha` block supports the following arguments:

* `custom_request_handling` - (Optional) Defines custom handling for the web request. See [Custom Request Handling](#custom-request-handling) below for details.

### Count

The `count` block supports the following arguments:
Expand Down