diff --git a/builtin/providers/aws/resource_aws_waf_size_constraint_set.go b/builtin/providers/aws/resource_aws_waf_size_constraint_set.go index 0e321bd6f..5e9f46dd4 100644 --- a/builtin/providers/aws/resource_aws_waf_size_constraint_set.go +++ b/builtin/providers/aws/resource_aws_waf_size_constraint_set.go @@ -115,12 +115,14 @@ func resourceAwsWafSizeConstraintSetRead(d *schema.ResourceData, meta interface{ func resourceAwsWafSizeConstraintSetUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).wafconn - o, n := d.GetChange("size_constraints") - oldS, newS := o.(*schema.Set).List(), n.(*schema.Set).List() + if d.HasChange("size_constraints") { + o, n := d.GetChange("size_constraints") + oldS, newS := o.(*schema.Set).List(), n.(*schema.Set).List() - err := updateSizeConstraintSetResource(d.Id(), oldS, newS, conn) - if err != nil { - return errwrap.Wrapf("[ERROR] Error updating SizeConstraintSet: {{err}}", err) + err := updateSizeConstraintSetResource(d.Id(), oldS, newS, conn) + if err != nil { + return errwrap.Wrapf("[ERROR] Error updating SizeConstraintSet: {{err}}", err) + } } return resourceAwsWafSizeConstraintSetRead(d, meta) diff --git a/builtin/providers/aws/resource_aws_waf_size_constraint_set_test.go b/builtin/providers/aws/resource_aws_waf_size_constraint_set_test.go index f309d7d3a..dcfac5d20 100644 --- a/builtin/providers/aws/resource_aws_waf_size_constraint_set_test.go +++ b/builtin/providers/aws/resource_aws_waf_size_constraint_set_test.go @@ -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 { return func(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).wafconn @@ -308,3 +331,10 @@ resource "aws_waf_size_constraint_set" "size_constraint_set" { } }`, name) } + +func testAccAWSWafSizeConstraintSetConfig_noConstraints(name string) string { + return fmt.Sprintf(` +resource "aws_waf_size_constraint_set" "size_constraint_set" { + name = "%s" +}`, name) +}