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

resources/wafregional_web_acl: add rule type support #4307

Merged
merged 1 commit into from
Jun 25, 2018
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
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