Skip to content

Commit

Permalink
Fix misidentification of parent folder at grandchild level or deeper. (
Browse files Browse the repository at this point in the history
…#32592)

* Fix misidentification of parent folder at grandchild level or deeper.

* Add changelog entry.

* r/aws_quicksight_folder(test): split parent folder tests, tidy configs

---------

Co-authored-by: Jared Baker <jared.baker@hashicorp.com>
  • Loading branch information
yosuke310 and jar-b committed Jul 20, 2023
1 parent f4669bd commit db5ffa9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/32592.txt
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_quicksight_folder: Fix misidentification of parent folder at grandchild level or deeper
```
2 changes: 1 addition & 1 deletion internal/service/quicksight/folder.go
Expand Up @@ -207,7 +207,7 @@ func resourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("name", out.Name)

if len(out.FolderPath) > 0 {
d.Set("parent_folder_arn", out.FolderPath[0])
d.Set("parent_folder_arn", out.FolderPath[len(out.FolderPath)-1])
}

if err := d.Set("folder_path", flex.FlattenStringList(out.FolderPath)); err != nil {
Expand Down
64 changes: 64 additions & 0 deletions internal/service/quicksight/folder_test.go
Expand Up @@ -241,6 +241,49 @@ func TestAccQuickSightFolder_parentFolder(t *testing.T) {
})
}

func TestAccQuickSightFolder_parentFolderNested(t *testing.T) {
ctx := acctest.Context(t)
var folder quicksight.Folder
rId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
parentId1 := rId + "-parent1"
parentName1 := rName + "-parent1"
parentId2 := rId + "-parent2"
parentName2 := rName + "-parent2"
resourceName := "aws_quicksight_folder.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, quicksight.EndpointsID)
},
ErrorCheck: acctest.ErrorCheck(t, quicksight.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckFolderDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccFolderConfig_parentFolder(rId, rName, parentId1, parentName1),
Check: resource.ComposeTestCheckFunc(
testAccCheckFolderExists(ctx, resourceName, &folder),
acctest.CheckResourceAttrRegionalARN(resourceName, "parent_folder_arn", "quicksight", fmt.Sprintf("folder/%s", parentId1)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccFolderConfig_parentFolder2(rId, rName, parentId1, parentName1, parentId2, parentName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckFolderExists(ctx, resourceName, &folder),
acctest.CheckResourceAttrRegionalARN(resourceName, "parent_folder_arn", "quicksight", fmt.Sprintf("folder/%s", parentId2)),
),
},
},
})
}

func testAccCheckFolderDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).QuickSightConn(ctx)
Expand Down Expand Up @@ -399,3 +442,24 @@ resource "aws_quicksight_folder" "test" {
}
`, rId, rName, parentId, parentName)
}

func testAccFolderConfig_parentFolder2(rId, rName, parentId1, parentName1, parentId2, parentName2 string) string {
return fmt.Sprintf(`
resource "aws_quicksight_folder" "parent" {
folder_id = %[3]q
name = %[4]q
}
resource "aws_quicksight_folder" "parent2" {
folder_id = %[5]q
name = %[6]q
parent_folder_arn = aws_quicksight_folder.parent.arn
}
resource "aws_quicksight_folder" "test" {
folder_id = %[1]q
name = %[2]q
parent_folder_arn = aws_quicksight_folder.parent2.arn
}
`, rId, rName, parentId1, parentName1, parentId2, parentName2)
}

0 comments on commit db5ffa9

Please sign in to comment.