provider/aws: Allow WAF SizeConstraint with no tuples

This commit is contained in:
Radek Simko 2017-04-29 10:52:07 +01:00
parent 3fb671be1f
commit bf99b53d17
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
2 changed files with 37 additions and 5 deletions

View File

@ -115,12 +115,14 @@ func resourceAwsWafSizeConstraintSetRead(d *schema.ResourceData, meta interface{
func resourceAwsWafSizeConstraintSetUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsWafSizeConstraintSetUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).wafconn conn := meta.(*AWSClient).wafconn
o, n := d.GetChange("size_constraints") if d.HasChange("size_constraints") {
oldS, newS := o.(*schema.Set).List(), n.(*schema.Set).List() o, n := d.GetChange("size_constraints")
oldS, newS := o.(*schema.Set).List(), n.(*schema.Set).List()
err := updateSizeConstraintSetResource(d.Id(), oldS, newS, conn) err := updateSizeConstraintSetResource(d.Id(), oldS, newS, conn)
if err != nil { if err != nil {
return errwrap.Wrapf("[ERROR] Error updating SizeConstraintSet: {{err}}", err) return errwrap.Wrapf("[ERROR] Error updating SizeConstraintSet: {{err}}", err)
}
} }
return resourceAwsWafSizeConstraintSetRead(d, meta) return resourceAwsWafSizeConstraintSetRead(d, meta)

View File

@ -161,6 +161,29 @@ func TestAccAWSWafSizeConstraintSet_changeConstraints(t *testing.T) {
}) })
} }
func TestAccAWSWafSizeConstraintSet_noConstraints(t *testing.T) {
var ipset waf.SizeConstraintSet
setName := fmt.Sprintf("sizeConstraintSet-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSWafSizeConstraintSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSWafSizeConstraintSetConfig_noConstraints(setName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafSizeConstraintSetExists("aws_waf_size_constraint_set.size_constraint_set", &ipset),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "name", setName),
resource.TestCheckResourceAttr(
"aws_waf_size_constraint_set.size_constraint_set", "size_constraints.#", "0"),
),
},
},
})
}
func testAccCheckAWSWafSizeConstraintSetDisappears(v *waf.SizeConstraintSet) resource.TestCheckFunc { func testAccCheckAWSWafSizeConstraintSetDisappears(v *waf.SizeConstraintSet) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).wafconn conn := testAccProvider.Meta().(*AWSClient).wafconn
@ -308,3 +331,10 @@ resource "aws_waf_size_constraint_set" "size_constraint_set" {
} }
}`, name) }`, name)
} }
func testAccAWSWafSizeConstraintSetConfig_noConstraints(name string) string {
return fmt.Sprintf(`
resource "aws_waf_size_constraint_set" "size_constraint_set" {
name = "%s"
}`, name)
}