diff --git a/.changelog/31393.txt b/.changelog/31393.txt new file mode 100644 index 00000000000..cc15d35befd --- /dev/null +++ b/.changelog/31393.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_rbin_rule: Fix crash when multiple `resource_tags` blocks are configured +``` \ No newline at end of file diff --git a/internal/service/rbin/rule.go b/internal/service/rbin/rule.go index e155884bdfb..9fec7e5055f 100644 --- a/internal/service/rbin/rule.go +++ b/internal/service/rbin/rule.go @@ -244,7 +244,7 @@ func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interf } if d.HasChanges("resource_tags") { - in.ResourceTags = expandResourceTags(d.Get("resource_tags").([]interface{})) + in.ResourceTags = expandResourceTags(d.Get("resource_tags").(*schema.Set).List()) update = true } diff --git a/internal/service/rbin/rule_test.go b/internal/service/rbin/rule_test.go index e31cf2d5a74..44e982e52f2 100644 --- a/internal/service/rbin/rule_test.go +++ b/internal/service/rbin/rule_test.go @@ -35,7 +35,7 @@ func TestAccRBinRule_basic(t *testing.T) { CheckDestroy: testAccCheckRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccRuleConfig_basic(description, resourceType), + Config: testAccRuleConfig_basic1(description, resourceType), Check: resource.ComposeTestCheckFunc( testAccCheckRuleExists(resourceName, &rule), resource.TestCheckResourceAttr(resourceName, "description", description), @@ -45,8 +45,8 @@ func TestAccRBinRule_basic(t *testing.T) { "retention_period_unit": "DAYS", }), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "resource_tags.*", map[string]string{ - "resource_tag_key": "some_tag", - "resource_tag_value": "", + "resource_tag_key": "some_tag1", + "resource_tag_value": "some_value1", }), ), }, @@ -55,6 +55,26 @@ func TestAccRBinRule_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccRuleConfig_basic2(description, resourceType), + Check: resource.ComposeTestCheckFunc( + testAccCheckRuleExists(resourceName, &rule), + resource.TestCheckResourceAttr(resourceName, "description", description), + resource.TestCheckResourceAttr(resourceName, "resource_type", resourceType), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "retention_period.*", map[string]string{ + "retention_period_value": "10", + "retention_period_unit": "DAYS", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "resource_tags.*", map[string]string{ + "resource_tag_key": "some_tag3", + "resource_tag_value": "some_value3", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "resource_tags.*", map[string]string{ + "resource_tag_key": "some_tag4", + "resource_tag_value": "some_value4", + }), + ), + }, }, }) } @@ -76,7 +96,7 @@ func TestAccRBinRule_disappears(t *testing.T) { CheckDestroy: testAccCheckRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccRuleConfig_basic(description, resourceType), + Config: testAccRuleConfig_basic1(description, resourceType), Check: resource.ComposeTestCheckFunc( testAccCheckRuleExists(resourceName, &rbinrule), acctest.CheckResourceDisappears(ctx, acctest.Provider, tfrbin.ResourceRule(), resourceName), @@ -218,15 +238,39 @@ func testAccCheckRuleExists(name string, rbinrule *rbin.GetRuleOutput) resource. } } -func testAccRuleConfig_basic(description, resourceType string) string { +func testAccRuleConfig_basic1(description, resourceType string) string { return fmt.Sprintf(` resource "aws_rbin_rule" "test" { description = %[1]q resource_type = %[2]q resource_tags { - resource_tag_key = "some_tag" - resource_tag_value = "" + resource_tag_key = "some_tag1" + resource_tag_value = "some_value1" + } + + retention_period { + retention_period_value = 10 + retention_period_unit = "DAYS" + } +} +`, description, resourceType) +} + +func testAccRuleConfig_basic2(description, resourceType string) string { + return fmt.Sprintf(` +resource "aws_rbin_rule" "test" { + description = %[1]q + resource_type = %[2]q + + resource_tags { + resource_tag_key = "some_tag3" + resource_tag_value = "some_value3" + } + + resource_tags { + resource_tag_key = "some_tag4" + resource_tag_value = "some_value4" } retention_period {