From bf99b53d1767331bb74d657f6d7904c6d12e326e Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Sat, 29 Apr 2017 10:52:07 +0100 Subject: [PATCH] provider/aws: Allow WAF SizeConstraint with no tuples --- .../resource_aws_waf_size_constraint_set.go | 12 ++++---- ...source_aws_waf_size_constraint_set_test.go | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) 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) +}