Skip to content

Commit

Permalink
resources/wafregional_web_acl: add rule type support
Browse files Browse the repository at this point in the history
This commit adds rule type support so that Rate Limit rules
could be use along with REGULAR rules.

Closes hashicorp#4079 hashicorp#4174 hashicorp#4052
  • Loading branch information
omeid committed Apr 22, 2018
1 parent 0095b64 commit 970a6c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aws/resource_aws_wafregional_web_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceAwsWafRegionalWebAcl() *schema.Resource {
Expand Down Expand Up @@ -63,6 +64,15 @@ func resourceAwsWafRegionalWebAcl() *schema.Resource {
Type: schema.TypeInt,
Required: true,
},
"type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: waf.WafRuleTypeRegular,
ValidateFunc: validation.StringInSlice([]string{
waf.WafRuleTypeRegular,
waf.WafRuleTypeRateBased,
}, false),
},
"rule_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -224,17 +234,20 @@ func flattenWafWebAclRules(ts []*waf.ActivatedRule) []interface{} {
m["action"] = []interface{}{actionMap}
m["priority"] = *r.Priority
m["rule_id"] = *r.RuleId
m["type"] = *r.Type
out[i] = m
}
return out
}

func expandWafWebAclUpdate(updateAction string, aclRule map[string]interface{}) *waf.WebACLUpdate {
ruleAction := aclRule["action"].([]interface{})[0].(map[string]interface{})

rule := &waf.ActivatedRule{
Action: &waf.WafAction{Type: aws.String(ruleAction["type"].(string))},
Priority: aws.Int64(int64(aclRule["priority"].(int))),
RuleId: aws.String(aclRule["rule_id"].(string)),
Type: aws.String(aclRule["type"].(string)),
}

update := &waf.WebACLUpdate{
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/wafregional_web_acl.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ resource "aws_wafregional_web_acl" "wafacl" {
priority = 1
rule_id = "${aws_wafregional_rule.wafrule.id}"
type = "REGULAR"
}
}
```
Expand All @@ -73,6 +74,7 @@ See [docs](https://docs.aws.amazon.com/waf/latest/APIReference/API_regional_Acti
* `priority` - (Required) Specifies the order in which the rules in a WebACL are evaluated.
Rules with a lower value are evaluated before rules with a higher value.
* `rule_id` - (Required) ID of the associated [rule](/docs/providers/aws/r/wafregional_rule.html)
* `type` - (Optional) The rule type, either `REGULAR`, as defined by [Rule](http://docs.aws.amazon.com/waf/latest/APIReference/API_Rule.html), or `RATE_BASED`, as defined by [RateBasedRule](http://docs.aws.amazon.com/waf/latest/APIReference/API_RateBasedRule.html). The default is REGULAR. If you add a RATE_BASED rule, you need to set `type` as `RATE_BASED`.

### `default_action` / `action`

Expand Down

0 comments on commit 970a6c9

Please sign in to comment.