provider/aws: Allow WAF Rule with no predicates

This commit is contained in:
Radek Simko 2017-04-29 08:39:18 +01:00
parent e520439215
commit 73839a6e0c
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
2 changed files with 39 additions and 5 deletions

View File

@ -129,13 +129,16 @@ func resourceAwsWafRuleRead(d *schema.ResourceData, meta interface{}) error {
func resourceAwsWafRuleUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).wafconn
o, n := d.GetChange("predicates")
oldP, newP := o.(*schema.Set).List(), n.(*schema.Set).List()
if d.HasChange("predicates") {
o, n := d.GetChange("predicates")
oldP, newP := o.(*schema.Set).List(), n.(*schema.Set).List()
err := updateWafRuleResource(d.Id(), oldP, newP, conn)
if err != nil {
return fmt.Errorf("Error Updating WAF Rule: %s", err)
err := updateWafRuleResource(d.Id(), oldP, newP, conn)
if err != nil {
return fmt.Errorf("Error Updating WAF Rule: %s", err)
}
}
return resourceAwsWafRuleRead(d, meta)
}

View File

@ -181,6 +181,29 @@ func testCheckResourceAttrWithIndexesAddr(name, format string, idx *int, value s
}
}
func TestAccAWSWafRule_noPredicates(t *testing.T) {
var rule waf.Rule
ruleName := fmt.Sprintf("wafrule%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafRuleConfig_noPredicates(ruleName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafRuleExists("aws_waf_rule.wafrule", &rule),
resource.TestCheckResourceAttr(
"aws_waf_rule.wafrule", "name", ruleName),
resource.TestCheckResourceAttr(
"aws_waf_rule.wafrule", "predicates.#", "0"),
),
},
},
})
}
func testAccCheckAWSWafRuleDisappears(v *waf.Rule) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).wafconn
@ -362,3 +385,11 @@ resource "aws_waf_rule" "wafrule" {
}
}`, name, name, name, name)
}
func testAccAWSWafRuleConfig_noPredicates(name string) string {
return fmt.Sprintf(`
resource "aws_waf_rule" "wafrule" {
name = "%s"
metric_name = "%s"
}`, name, name)
}