Skip to content

Commit

Permalink
New resource aws_quicksight_template
Browse files Browse the repository at this point in the history
  • Loading branch information
comtef committed Apr 13, 2023
1 parent e8b284b commit f0291f0
Show file tree
Hide file tree
Showing 40 changed files with 11,631 additions and 1 deletion.
28 changes: 28 additions & 0 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -27,6 +28,23 @@ func ExpandStringList(configured []interface{}) []*string {
return vs
}

// Takes the result of flatmap.Expand for an array of strings
// and returns a []*time.Time
func ExpandStringTimeList(configured []interface{}, format string) ([]*time.Time, error) {
vs := make([]*time.Time, 0, len(configured))
for _, v := range configured {
val, ok := v.(string)
if ok && val != "" {
t, err := time.Parse(format, v.(string))
if err != nil {
return nil, fmt.Errorf("error parsing date: %w", err)
}
vs = append(vs, aws.Time(t))
}
}
return vs, nil
}

// ExpandStringValueList takes the result of flatmap.Expand for an array of strings
// and returns a []string
func ExpandStringValueList(configured []interface{}) []string {
Expand Down Expand Up @@ -150,6 +168,16 @@ func ExpandInt64List(configured []interface{}) []*int64 {
return vs
}

// Takes the result of flatmap.Expand for an array of float64
// and returns a []*float64
func ExpandFloat64List(configured []interface{}) []*float64 {
vs := make([]*float64, 0, len(configured))
for _, v := range configured {
vs = append(vs, aws.Float64(float64(v.(float64))))
}
return vs
}

// Takes list of pointers to int64s. Expand to an array
// of raw ints and returns a []interface{}
// to keep compatibility w/ schema.NewSet
Expand Down
42 changes: 42 additions & 0 deletions internal/flex/flex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flex
import (
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -39,6 +40,47 @@ func TestExpandStringListEmptyItems(t *testing.T) {
}
}

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

configured := []interface{}{"2006-01-02T15:04:05+07:00", "2023-04-13T10:25:05+01:00"}
got, _ := ExpandStringTimeList(configured, time.RFC3339)
want := []*time.Time{
aws.Time(time.Date(2006, 1, 2, 15, 4, 5, 0, time.FixedZone("UTC-7", 7*60*60))),
aws.Time(time.Date(2023, 4, 13, 10, 25, 5, 0, time.FixedZone("UTC-1", 60*60))),
}

if !cmp.Equal(got, want) {
t.Errorf("expanded = %v, want = %v", got, want)
}
}

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

configured := []interface{}{"2006-01-02T15:04:05+07:00", "", "2023-04-13T10:25:05+01:00"}
got, _ := ExpandStringTimeList(configured, time.RFC3339)
want := []*time.Time{
aws.Time(time.Date(2006, 1, 2, 15, 4, 5, 0, time.FixedZone("UTC+7", 7*60*60))),
aws.Time(time.Date(2023, 4, 13, 10, 25, 5, 0, time.FixedZone("UTC+1", 60*60))),
}

if !cmp.Equal(got, want) {
t.Errorf("expanded = %v, want = %v", got, want)
}
}

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

configured := []interface{}{"abc"}
_, err := ExpandStringTimeList(configured, time.RFC3339)

if err == nil {
t.Error("Expecting format error")
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion internal/service/quicksight/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func resourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interf
})

if err != nil {
return diag.Errorf("error describing QuickSight Data Source (%s) Permissions: %s", d.Id(), err)
return diag.Errorf("error describing QuickSight Folder (%s) Permissions: %s", d.Id(), err)
}

if err := d.Set("permissions", flattenPermissions(permsResp.Permissions)); err != nil {
Expand Down
Loading

0 comments on commit f0291f0

Please sign in to comment.