Skip to content

Commit

Permalink
New resource aws_quicksight_folder (#30400)
Browse files Browse the repository at this point in the history
* New resource aws_quicksight_folder

* r/aws_quicksight_folder: name required on create

* r/aws_quicksight_folder: rm short test gate

* r/aws_quicksight_folder: finder accepts id directly

* r/aws_quicksight_folder: tag update test

* r/aws_quicksight_data_set: fix tag update, add test

* r/aws_quicksight_folder: parent_folder_arn update test

---------

Co-authored-by: Jared Baker <jared.baker@hashicorp.com>
  • Loading branch information
comtef and jar-b authored Apr 3, 2023
1 parent b9980e9 commit 6716a0a
Show file tree
Hide file tree
Showing 11 changed files with 1,222 additions and 284 deletions.
3 changes: 3 additions & 0 deletions .changelog/30400.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_quicksight_folder
```
19 changes: 2 additions & 17 deletions internal/service/quicksight/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func ResourceDataSet() *schema.Resource {
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
},
CustomizeDiff: verify.SetTagsDiff,
}
}

Expand Down Expand Up @@ -795,7 +796,7 @@ func resourceDataSetCreate(ctx context.Context, d *schema.ResourceData, meta int
}

if v, ok := d.GetOk("permissions"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.Permissions = expandDataSetPermissions(v.([]interface{}))
input.Permissions = expandResourcePermissions(v.([]interface{}))
}

if v, ok := d.GetOk("row_level_permission_data_set"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
Expand Down Expand Up @@ -1710,22 +1711,6 @@ func expandDataSetUploadSettings(tfMap map[string]interface{}) *quicksight.Uploa
return uploadSettings
}

func expandDataSetPermissions(tfList []interface{}) []*quicksight.ResourcePermission {
permissions := make([]*quicksight.ResourcePermission, len(tfList))

for i, tfListRaw := range tfList {
tfMap := tfListRaw.(map[string]interface{})

permission := &quicksight.ResourcePermission{
Actions: flex.ExpandStringSet(tfMap["actions"].(*schema.Set)),
Principal: aws.String(tfMap["principal"].(string)),
}

permissions[i] = permission
}
return permissions
}

func expandDataSetRowLevelPermissionDataSet(tfList []interface{}) *quicksight.RowLevelPermissionDataSet {
if len(tfList) == 0 || tfList[0] == nil {
return nil
Expand Down
53 changes: 50 additions & 3 deletions internal/service/quicksight/data_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestAccQuickSightDataSet_tags(t *testing.T) {
CheckDestroy: testAccCheckDataSetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDataSetConfigTags(rId, rName, "key1", "value1"),
Config: testAccDataSetConfigTags1(rId, rName, "key1", "value1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
Expand All @@ -366,6 +366,23 @@ func TestAccQuickSightDataSet_tags(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataSetConfigTags2(rId, rName, "key1", "value1updated", "key2", "value2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"),
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),
),
},
{
Config: testAccDataSetConfigTags1(rId, rName, "key2", "value2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"),
),
},
},
})
}
Expand Down Expand Up @@ -770,7 +787,36 @@ resource "aws_quicksight_data_set" "test" {
`, rId, rName))
}

func testAccDataSetConfigTags(rId, rName, key, value string) string {
func testAccDataSetConfigTags1(rId, rName, key1, value1 string) string {
return acctest.ConfigCompose(
testAccDataSetConfigBase(rId, rName),
fmt.Sprintf(`
resource "aws_quicksight_data_set" "test" {
data_set_id = %[1]q
name = %[2]q
import_mode = "SPICE"
physical_table_map {
physical_table_map_id = %[1]q
s3_source {
data_source_arn = aws_quicksight_data_source.test.arn
input_columns {
name = "Column1"
type = "STRING"
}
upload_settings {
format = "JSON"
}
}
}
tags = {
%[3]q = %[4]q
}
}
`, rId, rName, key1, value1))
}

func testAccDataSetConfigTags2(rId, rName, key1, value1, key2, value2 string) string {
return acctest.ConfigCompose(
testAccDataSetConfigBase(rId, rName),
fmt.Sprintf(`
Expand All @@ -794,7 +840,8 @@ resource "aws_quicksight_data_set" "test" {
}
tags = {
%[3]q = %[4]q
%[5]q = %[6]q
}
}
`, rId, rName, key, value))
`, rId, rName, key1, value1, key2, value2))
}
47 changes: 1 addition & 46 deletions internal/service/quicksight/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -632,7 +631,7 @@ func resourceDataSourceCreate(ctx context.Context, d *schema.ResourceData, meta
}

if v, ok := d.GetOk("permission"); ok && v.(*schema.Set).Len() > 0 {
params.Permissions = expandDataSourcePermissions(v.(*schema.Set).List())
params.Permissions = expandResourcePermissions(v.(*schema.Set).List())
}

if v, ok := d.GetOk("ssl_properties"); ok && len(v.([]interface{})) != 0 && v.([]interface{})[0] != nil {
Expand Down Expand Up @@ -1274,22 +1273,6 @@ func expandDataSourceParameters(tfList []interface{}) *quicksight.DataSourcePara
return dataSourceParams
}

func expandDataSourcePermissions(tfList []interface{}) []*quicksight.ResourcePermission {
permissions := make([]*quicksight.ResourcePermission, len(tfList))

for i, tfListRaw := range tfList {
tfMap := tfListRaw.(map[string]interface{})
permission := &quicksight.ResourcePermission{
Actions: flex.ExpandStringSet(tfMap["actions"].(*schema.Set)),
Principal: aws.String(tfMap["principal"].(string)),
}

permissions[i] = permission
}

return permissions
}

func expandDataSourceSSLProperties(tfList []interface{}) *quicksight.SslProperties {
if len(tfList) == 0 {
return nil
Expand Down Expand Up @@ -1570,34 +1553,6 @@ func flattenParameters(parameters *quicksight.DataSourceParameters) []interface{
return params
}

func flattenPermissions(perms []*quicksight.ResourcePermission) []interface{} {
if len(perms) == 0 {
return []interface{}{}
}

values := make([]interface{}, 0)

for _, p := range perms {
if p == nil {
continue
}

perm := make(map[string]interface{})

if p.Principal != nil {
perm["principal"] = aws.StringValue(p.Principal)
}

if p.Actions != nil {
perm["actions"] = flex.FlattenStringList(p.Actions)
}

values = append(values, perm)
}

return values
}

func flattenSSLProperties(props *quicksight.SslProperties) []interface{} {
if props == nil {
return []interface{}{}
Expand Down
Loading

0 comments on commit 6716a0a

Please sign in to comment.