Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_rbin_rule: Fix multiple resource tag panic #31393

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/31393.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_rbin_rule: Fix crash when multiple `resource_tags` blocks are configured
```
2 changes: 1 addition & 1 deletion internal/service/rbin/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
58 changes: 51 additions & 7 deletions internal/service/rbin/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
}),
),
},
Expand All @@ -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",
}),
),
},
},
})
}
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down