Skip to content

Commit

Permalink
New resource aws_quicksight_folder
Browse files Browse the repository at this point in the history
  • Loading branch information
comtef committed Apr 3, 2023
1 parent bea2cb0 commit 9c27944
Show file tree
Hide file tree
Showing 10 changed files with 1,160 additions and 281 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
```
18 changes: 1 addition & 17 deletions internal/service/quicksight/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,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 +1710,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
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
213 changes: 0 additions & 213 deletions internal/service/quicksight/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package quicksight_test
import (
"context"
"fmt"
"reflect"
"regexp"
"testing"

Expand All @@ -12,224 +11,12 @@ import (
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfquicksight "github.com/hashicorp/terraform-provider-aws/internal/service/quicksight"
)

func TestDataSourcePermissionsDiff(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
oldPermissions []interface{}
newPermissions []interface{}
expectedGrants []*quicksight.ResourcePermission
expectedRevokes []*quicksight.ResourcePermission
}{
{
name: "no changes;empty",
oldPermissions: []interface{}{},
newPermissions: []interface{}{},
expectedGrants: nil,
expectedRevokes: nil,
},
{
name: "no changes;same",
oldPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
},
newPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
}},

expectedGrants: nil,
expectedRevokes: nil,
},
{
name: "grant only",
oldPermissions: []interface{}{},
newPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
},
expectedGrants: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"action1", "action2"}),
Principal: aws.String("principal1"),
},
},
expectedRevokes: nil,
},
{
name: "revoke only",
oldPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
},
newPermissions: []interface{}{},
expectedGrants: nil,
expectedRevokes: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"action1", "action2"}),
Principal: aws.String("principal1"),
},
},
},
{
name: "grant new action",
oldPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
}),
},
},
newPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
},
expectedGrants: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"action2"}),
Principal: aws.String("principal1"),
},
},
expectedRevokes: nil,
},
{
name: "revoke old action",
oldPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"oldAction",
"onlyOldAction",
}),
},
},
newPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"oldAction",
}),
},
},
expectedGrants: nil,
expectedRevokes: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"onlyOldAction"}),
Principal: aws.String("principal1"),
},
},
},
{
name: "multiple permissions",
oldPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
map[string]interface{}{
"principal": "principal2",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action3",
"action4",
}),
},
map[string]interface{}{
"principal": "principal3",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action5",
}),
},
},
newPermissions: []interface{}{
map[string]interface{}{
"principal": "principal1",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action1",
"action2",
}),
},
map[string]interface{}{
"principal": "principal2",
"actions": schema.NewSet(schema.HashString, []interface{}{
"action3",
"action5",
}),
},
},
expectedGrants: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"action5"}),
Principal: aws.String("principal2"),
},
},
expectedRevokes: []*quicksight.ResourcePermission{
{
Actions: aws.StringSlice([]string{"action1", "action4"}),
Principal: aws.String("principal2"),
},
{
Actions: aws.StringSlice([]string{"action5"}),
Principal: aws.String("principal3"),
},
},
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

toGrant, toRevoke := tfquicksight.DiffPermissions(testCase.oldPermissions, testCase.newPermissions)
if !reflect.DeepEqual(toGrant, testCase.expectedGrants) {
t.Fatalf("Expected: %v, got: %v", testCase.expectedGrants, toGrant)
}

if !reflect.DeepEqual(toRevoke, testCase.expectedRevokes) {
t.Fatalf("Expected: %v, got: %v", testCase.expectedRevokes, toRevoke)
}
})
}
}

func TestAccQuickSightDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
var dataSource quicksight.DataSource
Expand Down
Loading

0 comments on commit 9c27944

Please sign in to comment.