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 20, 2023
1 parent 8f6109b commit fd63614
Show file tree
Hide file tree
Showing 45 changed files with 20,959 additions and 2 deletions.
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
22 changes: 21 additions & 1 deletion internal/service/quicksight/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ resource "aws_s3_bucket_acl" "test" {
acl = "public-read"
}
resource "aws_s3_object" "test_data" {
depends_on = [aws_s3_bucket_acl.test]
bucket = aws_s3_bucket.test.bucket
key = "%[1]s-test-data"
content = <<EOF
[
{
"Column1": "aaa",
"Column2": 1
},
{
"Column1": "bbb",
"Column2": 1
}
]
EOF
acl = "public-read"
}
resource "aws_s3_object" "test" {
depends_on = [aws_s3_bucket_acl.test]
Expand All @@ -306,7 +326,7 @@ resource "aws_s3_object" "test" {
"fileLocations": [
{
"URIs": [
"https://${aws_s3_bucket.test.bucket}.s3.${data.aws_partition.current.dns_suffix}/%[1]s"
"https://${aws_s3_bucket.test.bucket}.s3.${data.aws_partition.current.dns_suffix}/%[1]s-test-data"
]
}
],
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 @@ -217,7 +217,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
4 changes: 4 additions & 0 deletions internal/service/quicksight/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions internal/service/quicksight/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/quicksight"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

// status fetches the DataSource and its Status
Expand All @@ -29,3 +30,19 @@ func status(ctx context.Context, conn *quicksight.QuickSight, accountId, datasou
return output.DataSource, aws.StringValue(output.DataSource.Status), nil
}
}

// Fetch Template status
func statusTemplate(ctx context.Context, conn *quicksight.QuickSight, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
out, err := FindTemplateByID(ctx, conn, id)
if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return out, *out.Version.Status, nil
}
}
Loading

0 comments on commit fd63614

Please sign in to comment.