From b3a33188d1cf796ae8f1b1cce1f63da33ad39a1e Mon Sep 17 00:00:00 2001 From: Dedunu Dhananjaya Date: Fri, 12 May 2023 21:19:30 +0300 Subject: [PATCH 1/3] Update rule.go --- internal/service/rbin/rule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From 6d850cb57ef775cf0c8062d962d57de78cccab3c Mon Sep 17 00:00:00 2001 From: Dedunu Dhananjaya Date: Fri, 12 May 2023 21:21:14 +0300 Subject: [PATCH 2/3] Update rule_test.go --- internal/service/rbin/rule_test.go | 58 ++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 7 deletions(-) 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 { From 15b5442264a9d5e56eea649dda1a20fc6239f3be Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 19 May 2023 09:43:04 -0400 Subject: [PATCH 3/3] Add CHANGELOG entry. --- .changelog/31393.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/31393.txt 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