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

Add support for challenge_config in wafv2_web_acl #35367

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/35367.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_wafv2_web_acl: Add `challenge_config` argument
```
43 changes: 43 additions & 0 deletions internal/service/wafv2/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ func expandCaptchaConfig(l []interface{}) *wafv2.CaptchaConfig {
return configuration
}

func expandChallengeConfig(l []interface{}) *wafv2.ChallengeConfig {
configuration := &wafv2.ChallengeConfig{}

if len(l) == 0 || l[0] == nil {
return configuration
}

m := l[0].(map[string]interface{})
if v, ok := m["immunity_time_property"]; ok {
inner := v.([]interface{})
if len(inner) == 0 || inner[0] == nil {
return configuration
}

m = inner[0].(map[string]interface{})

if v, ok := m["immunity_time"]; ok {
configuration.ImmunityTimeProperty = &wafv2.ImmunityTimeProperty{
ImmunityTime: aws.Int64(int64(v.(int))),
}
}
}

return configuration
}

func expandAssociationConfig(l []interface{}) *wafv2.AssociationConfig {
if len(l) == 0 || l[0] == nil {
return nil
Expand Down Expand Up @@ -1655,6 +1681,23 @@ func flattenCaptchaConfig(config *wafv2.CaptchaConfig) interface{} {
return []interface{}{m}
}

func flattenChallengeConfig(config *wafv2.ChallengeConfig) interface{} {
if config == nil {
return []interface{}{}
}
if config.ImmunityTimeProperty == nil {
return []interface{}{}
}

m := map[string]interface{}{
"immunity_time_property": []interface{}{map[string]interface{}{
"immunity_time": aws.Int64Value(config.ImmunityTimeProperty.ImmunityTime),
}},
}

return []interface{}{m}
}

func flattenAssociationConfig(config *wafv2.AssociationConfig) interface{} {
associationConfig := []interface{}{}
if config == nil {
Expand Down
25 changes: 25 additions & 0 deletions internal/service/wafv2/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,31 @@ func challengeConfigSchema() *schema.Schema {
}
}

func outerChallengeConfigSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"immunity_time_property": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"immunity_time": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
},
},
}
}

func countConfigSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down
6 changes: 6 additions & 0 deletions internal/service/wafv2/web_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func ResourceWebACL() *schema.Resource {
Computed: true,
},
"captcha_config": outerCaptchaConfigSchema(),
"challenge_config": outerChallengeConfigSchema(),
"custom_response_body": customResponseBodySchema(),
"default_action": {
Type: schema.TypeList,
Expand Down Expand Up @@ -179,6 +180,7 @@ func resourceWebACLCreate(ctx context.Context, d *schema.ResourceData, meta inte
input := &wafv2.CreateWebACLInput{
AssociationConfig: expandAssociationConfig(d.Get("association_config").([]interface{})),
CaptchaConfig: expandCaptchaConfig(d.Get("captcha_config").([]interface{})),
ChallengeConfig: expandChallengeConfig(d.Get("challenge_config").([]interface{})),
DefaultAction: expandDefaultAction(d.Get("default_action").([]interface{})),
Name: aws.String(name),
Rules: expandWebACLRules(d.Get("rule").(*schema.Set).List()),
Expand Down Expand Up @@ -239,6 +241,9 @@ func resourceWebACLRead(ctx context.Context, d *schema.ResourceData, meta interf
if err := d.Set("captcha_config", flattenCaptchaConfig(webACL.CaptchaConfig)); err != nil {
return diag.Errorf("setting captcha_config: %s", err)
}
if err := d.Set("challenge_config", flattenChallengeConfig(webACL.ChallengeConfig)); err != nil {
return diag.Errorf("setting challenge_config: %s", err)
}
if err := d.Set("custom_response_body", flattenCustomResponseBodies(webACL.CustomResponseBodies)); err != nil {
return diag.Errorf("setting custom_response_body: %s", err)
}
Expand Down Expand Up @@ -282,6 +287,7 @@ func resourceWebACLUpdate(ctx context.Context, d *schema.ResourceData, meta inte
input := &wafv2.UpdateWebACLInput{
AssociationConfig: expandAssociationConfig(d.Get("association_config").([]interface{})),
CaptchaConfig: expandCaptchaConfig(d.Get("captcha_config").([]interface{})),
ChallengeConfig: expandChallengeConfig(d.Get("challenge_config").([]interface{})),
DefaultAction: expandDefaultAction(d.Get("default_action").([]interface{})),
Id: aws.String(aclID),
LockToken: aws.String(aclLockToken),
Expand Down
8 changes: 8 additions & 0 deletions internal/service/wafv2/web_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccWAFV2WebACL_basic(t *testing.T) {
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "wafv2", regexache.MustCompile(`regional/webacl/.+$`)),
resource.TestCheckResourceAttr(resourceName, "association_config.#", "0"),
resource.TestCheckResourceAttr(resourceName, "captcha_config.#", "0"),
resource.TestCheckResourceAttr(resourceName, "challenge_config.#", "0"),
resource.TestCheckResourceAttr(resourceName, "default_action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "default_action.0.allow.#", "1"),
resource.TestCheckResourceAttr(resourceName, "default_action.0.block.#", "0"),
Expand Down Expand Up @@ -2441,6 +2442,7 @@ func TestAccWAFV2WebACL_Custom_requestHandling(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "visibility_config.0.sampled_requests_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "captcha_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "captcha_config.0.immunity_time_property.0.immunity_time", "120"),
resource.TestCheckResourceAttr(resourceName, "challenge_config.0.immunity_time_property.0.immunity_time", "300"),
),
},
{
Expand Down Expand Up @@ -3572,6 +3574,12 @@ resource "aws_wafv2_web_acl" "test" {
immunity_time = 120
}
}

challenge_config {
immunity_time_property {
immunity_time = 300
}
}
}
`, rName, firstHeader, secondHeader)
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/wafv2_web_acl.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ resource "aws_wafv2_web_acl" "test" {
This resource supports the following arguments:

* `association_config` - (Optional) Specifies custom configurations for the associations between the web ACL and protected resources. See [`association_config`](#association_config-block) below for details.
* `captcha_config` - (Optional) Specifies how AWS WAF should handle CAPTCHA evaluations on the ACL level (used by [AWS Bot Control](https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-bot.html)). See [`captcha_config`](#captcha_config-block) below for details.
* `challenge_config` - (Optional) Specifies how AWS WAF should handle Challenge evaluations on the ACL level (used by [AWS Bot Control](https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-bot.html)). See [`challenge_config`](#challenge_config-block) below for details.
* `custom_response_body` - (Optional) Defines custom response bodies that can be referenced by `custom_response` actions. See [`custom_response_body`](#custom_response_body-block) below for details.
* `default_action` - (Required) Action to perform if none of the `rules` contained in the WebACL match. See [`default_action`](#default_action-block) below for details.
* `description` - (Optional) Friendly description of the WebACL.
Expand Down Expand Up @@ -928,6 +930,12 @@ The `captcha_config` block supports the following arguments:

* `immunity_time_property` - (Optional) Defines custom immunity time. See [`immunity_time_property`](#immunity_time_property-block) below for details.

### `challenge_config` Block

The `challenge_config` block supports the following arguments:

* `immunity_time_property` - (Optional) Defines custom immunity time. See [`immunity_time_property`](#immunity_time_property-block) below for details.

### `immunity_time_property` Block

The `immunity_time_property` block supports the following arguments:
Expand Down
Loading