From 970a6c953bf048aa94bbedc44027d1d9ed096992 Mon Sep 17 00:00:00 2001 From: omeid matten Date: Sun, 22 Apr 2018 21:05:06 +1000 Subject: [PATCH] resources/wafregional_web_acl: add rule type support This commit adds rule type support so that Rate Limit rules could be use along with REGULAR rules. Closes #4079 #4174 #4052 --- aws/resource_aws_wafregional_web_acl.go | 13 +++++++++++++ website/docs/r/wafregional_web_acl.html.markdown | 2 ++ 2 files changed, 15 insertions(+) diff --git a/aws/resource_aws_wafregional_web_acl.go b/aws/resource_aws_wafregional_web_acl.go index d466b14d95d0..ff72c1d1cebc 100644 --- a/aws/resource_aws_wafregional_web_acl.go +++ b/aws/resource_aws_wafregional_web_acl.go @@ -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 { @@ -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, @@ -224,6 +234,7 @@ 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 @@ -231,10 +242,12 @@ func flattenWafWebAclRules(ts []*waf.ActivatedRule) []interface{} { 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{ diff --git a/website/docs/r/wafregional_web_acl.html.markdown b/website/docs/r/wafregional_web_acl.html.markdown index a93506a9b3c0..2eeedef39a3f 100644 --- a/website/docs/r/wafregional_web_acl.html.markdown +++ b/website/docs/r/wafregional_web_acl.html.markdown @@ -48,6 +48,7 @@ resource "aws_wafregional_web_acl" "wafacl" { priority = 1 rule_id = "${aws_wafregional_rule.wafrule.id}" + type = "REGULAR" } } ``` @@ -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`