Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource aws_quicksight_template #30453

Merged
merged 42 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f02eb81
New resource aws_quicksight_template
comtef Apr 4, 2023
6e630f2
r/aws_quicksight_template: move schemas to subdirectory
jar-b Apr 26, 2023
2a7fac4
r/aws_quicksight_template: flatten definition
comtef Apr 28, 2023
9fefc52
r/aws_quicksight_template: sheet filter_controls flatteners
jar-b May 2, 2023
4c750b3
r/aws_quicksight_template: sheet layouts flatteners
jar-b May 2, 2023
6033fd0
r/aws_quicksight_template: sheet parameter_controls flatteners
jar-b May 3, 2023
0792b6f
r/aws_quicksight_template: sheet sheet_control_layouts flatteners
jar-b May 3, 2023
b0887f0
r/aws_quicksight_template: sheet text_boxes flattener
jar-b May 3, 2023
7fac3db
r/aws_quicksight_template: frame out root visuals flatteners
jar-b May 3, 2023
3140ad4
r/aws_quicksight_template: visual bar_chart configration flatteners
jar-b May 3, 2023
03c04de
r/aws_quicksight_template: visual bar_chart flatteners
jar-b May 4, 2023
513f5a7
r/aws_quicksight_template: visual box_plot flatteners
jar-b May 4, 2023
2f5471a
r/aws_quicksight_template: sheets optional/computed attributes
jar-b May 4, 2023
050cfc9
r/aws_quicksight_template: visual combo_chart flatteners
jar-b May 4, 2023
83c2015
r/aws_quicksight_template: visual custom_content flatteners
jar-b May 4, 2023
35505ad
r/aws_quicksight_template: visual empty flattener
jar-b May 4, 2023
4dbedfd
r/aws_quicksight_template: visual filled_map flatteners
jar-b May 4, 2023
29b7297
r/aws_quicksight_template: visual funnel_chart flatteners
jar-b May 4, 2023
b131ae5
r/aws_quicksight_template: visual gauge_chart flatteners
jar-b May 4, 2023
49a4411
r/aws_quicksight_template: computed, empty API response handling
jar-b May 5, 2023
6ac9a55
r/aws_quicksight_template: visual geospatial_map flatteners
jar-b May 5, 2023
48d868d
r/aws_quicksight_template: visual heat_map flatteners
jar-b May 5, 2023
cfb5cf9
r/aws_quicksight_template: visual histogram flatteners
jar-b May 5, 2023
e92414b
r/aws_quicksight_template: visual insight flatteners
jar-b May 5, 2023
c07bc29
r/aws_quicksight_template: visual kpi flatteners
jar-b May 5, 2023
561c8e1
r/aws_quicksight_template: visual line_chart flatteners
jar-b May 5, 2023
5953a17
r/aws_quicksight_template: visual pie_chart flatteners
jar-b May 8, 2023
fcfba5c
r/aws_quicksight_template: visual pivot_table flatteners
jar-b May 8, 2023
1e1b978
r/aws_quicksight_template: visual radar_chart flatteners
jar-b May 8, 2023
fc53c8b
r/aws_quicksight_template: visual sankey_diagram flatteners
jar-b May 8, 2023
c58f30c
r/aws_quicksight_template: visual scatter_plot flatteners
jar-b May 8, 2023
502f77a
r/aws_quicksight_template: visual table flatteners
jar-b May 8, 2023
9a44fe5
r/aws_quicksight_template: visual tree_map flatteners
jar-b May 8, 2023
0b97511
r/aws_quicksight_template: visual waterfall flatteners
jar-b May 8, 2023
5dc5ded
r/aws_quicksight_template: visual word_cloud flatteners
jar-b May 8, 2023
eb39355
r/aws_quicksight_template: expander cleanup, schema adjustments
jar-b May 8, 2023
5b3d53f
Merge branch 'main' into f_aws_quicksight_template
jar-b May 8, 2023
c3a76ac
r/aws_quicksight_template: prefer DiffSuppressFunc over empty struct …
jar-b May 8, 2023
bad2bca
r/aws_quicksight_template: suppress default sort configuration diff
jar-b May 9, 2023
44a2a61
r/aws_quicksight_template: import support
jar-b May 9, 2023
9df92a0
r/aws_quicksight_template: transparent tagging, tags tests
jar-b May 9, 2023
61eb759
r/aws_quicksight_template: tidy test names
jar-b May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/30453.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_quicksight_template
```
46 changes: 46 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,20 @@ 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 {
vs := make([]*time.Time, 0, len(configured))
for _, v := range configured {
val, ok := v.(string)
if ok && val != "" {
t, _ := time.Parse(format, v.(string))
vs = append(vs, aws.Time(t))
}
}
return vs
}

// 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 @@ -54,6 +69,16 @@ func FlattenStringList(list []*string) []interface{} {
return vs
}

// Takes list of pointers to time.Time. Expand to an array
// of strings and returns a []interface{}
func FlattenTimeStringList(list []*time.Time, format string) []interface{} {
vs := make([]interface{}, 0, len(list))
for _, v := range list {
vs = append(vs, v.Format(format))
}
return vs
}

// Takes list of strings. Expand to an array
// of raw strings and returns a []interface{}
// to keep compatibility w/ schema.NewSetschema.NewSet
Expand Down Expand Up @@ -150,6 +175,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(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 All @@ -161,6 +196,17 @@ func FlattenInt64List(list []*int64) []interface{} {
return vs
}

// Takes list of pointers to float64s. Expand to an array
// of raw floats and returns a []interface{}
// to keep compatibility w/ schema.NewSet
func FlattenFloat64List(list []*float64) []interface{} {
vs := make([]interface{}, 0, len(list))
for _, v := range list {
vs = append(vs, int(aws.Float64Value(v)))
}
return vs
}

func PointersMapToStringList(pointers map[string]*string) map[string]interface{} {
list := make(map[string]interface{}, len(pointers))
for i, v := range pointers {
Expand Down
46 changes: 46 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,36 @@ 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 TestExpandStringValueList(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -156,3 +187,18 @@ func TestFlattenResourceIdSinglePart(t *testing.T) {
t.Fatalf("Expected an error when parsing ResourceId with single part count")
}
}

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

configured := []*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))),
}
got := FlattenTimeStringList(configured, time.RFC3339)
want := []interface{}{"2006-01-02T15:04:05+07:00", "2023-04-13T10:25:05+01:00"}

if !cmp.Equal(got, want) {
t.Errorf("expanded = %v, want = %v", got, want)
}
}
87 changes: 63 additions & 24 deletions internal/service/quicksight/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ func ResourceDataSet() *schema.Resource {
Required: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"output_columns": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"permissions": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -869,6 +889,10 @@ func resourceDataSetRead(ctx context.Context, d *schema.ResourceData, meta inter
return diag.Errorf("error setting logical_table_map: %s", err)
}

if err := d.Set("output_columns", flattenOutputColumns(dataSet.OutputColumns)); err != nil {
return diag.Errorf("error setting output_columns: %s", err)
}

if err := d.Set("physical_table_map", flattenPhysicalTableMap(dataSet.PhysicalTableMap, physicalTableMapSchema())); err != nil {
return diag.Errorf("error setting physical_table_map: %s", err)
}
Expand Down Expand Up @@ -913,33 +937,19 @@ func resourceDataSetUpdate(ctx context.Context, d *schema.ResourceData, meta int
Name: aws.String(d.Get("name").(string)),
}

if d.HasChange("column_groups") {
params.ColumnGroups = expandDataSetColumnGroups(d.Get("column_groups").([]interface{}))
}
params.ColumnGroups = expandDataSetColumnGroups(d.Get("column_groups").([]interface{}))

if d.HasChange("column_level_permission_rules") {
params.ColumnLevelPermissionRules = expandDataSetColumnLevelPermissionRules(d.Get("column_level_permission_rules").([]interface{}))
}
params.ColumnLevelPermissionRules = expandDataSetColumnLevelPermissionRules(d.Get("column_level_permission_rules").([]interface{}))

if d.HasChange("data_set_usage_configuration") {
params.DataSetUsageConfiguration = expandDataSetUsageConfiguration(d.Get("data_set_usage_configuration").([]interface{}))
}
params.DataSetUsageConfiguration = expandDataSetUsageConfiguration(d.Get("data_set_usage_configuration").([]interface{}))

if d.HasChange("field_folders") {
params.FieldFolders = expandDataSetFieldFolders(d.Get("field_folders").(*schema.Set).List())
}
params.FieldFolders = expandDataSetFieldFolders(d.Get("field_folders").(*schema.Set).List())

if d.HasChange("logical_table_map") {
params.LogicalTableMap = expandDataSetLogicalTableMap(d.Get("logical_table_map").(*schema.Set))
}
params.LogicalTableMap = expandDataSetLogicalTableMap(d.Get("logical_table_map").(*schema.Set))

if d.HasChange("row_level_permission_data_set") {
params.RowLevelPermissionDataSet = expandDataSetRowLevelPermissionDataSet(d.Get("row_level_permission_data_set").([]interface{}))
}
params.RowLevelPermissionDataSet = expandDataSetRowLevelPermissionDataSet(d.Get("row_level_permission_data_set").([]interface{}))

if d.HasChange("row_level_permission_tag_configuration") {
params.RowLevelPermissionTagConfiguration = expandDataSetRowLevelPermissionTagConfigurations(d.Get("row_level_permission_tag_configuration").([]interface{}))
}
params.RowLevelPermissionTagConfiguration = expandDataSetRowLevelPermissionTagConfigurations(d.Get("row_level_permission_tag_configuration").([]interface{}))

_, err = conn.UpdateDataSetWithContext(ctx, params)
if err != nil {
Expand Down Expand Up @@ -1671,8 +1681,8 @@ func expandDataSetUploadSettings(tfMap map[string]interface{}) *quicksight.Uploa
if v, ok := tfMap["format"].(string); ok {
uploadSettings.Format = aws.String(v)
}
if v, ok := tfMap["start_from_row"].(int64); ok {
uploadSettings.StartFromRow = aws.Int64(v)
if v, ok := tfMap["start_from_row"].(int); ok {
uploadSettings.StartFromRow = aws.Int64(int64(v))
}
if v, ok := tfMap["text_qualifier"].(string); ok {
uploadSettings.TextQualifier = aws.String(v)
Expand Down Expand Up @@ -1797,6 +1807,35 @@ func flattenColumnGroups(apiObject []*quicksight.ColumnGroup) []interface{} {
return tfList
}

func flattenOutputColumns(apiObject []*quicksight.OutputColumn) []interface{} {
if len(apiObject) == 0 {
return nil
}

var tfList []interface{}
for _, column := range apiObject {
if column == nil {
continue
}

item := map[string]interface{}{}

if column.Description != nil {
item["description"] = aws.StringValue(column.Description)
}
if column.Name != nil {
item["name"] = aws.StringValue(column.Name)
}
if column.Type != nil {
item["type"] = aws.StringValue(column.Type)
}

tfList = append(tfList, item)
}

return tfList
}

func flattenGeoSpatialColumnGroup(apiObject *quicksight.GeoSpatialColumnGroup) []interface{} {
if apiObject == nil {
return nil
Expand Down Expand Up @@ -2328,7 +2367,7 @@ func flattenUploadSettings(apiObject *quicksight.UploadSettings) []interface{} {
tfMap["contains_header"] = aws.BoolValue(apiObject.ContainsHeader)
}
if apiObject.Delimiter != nil {
tfMap["contains_header"] = aws.StringValue(apiObject.Delimiter)
tfMap["delimiter"] = aws.StringValue(apiObject.Delimiter)
}
if apiObject.Format != nil {
tfMap["format"] = aws.StringValue(apiObject.Format)
Expand Down
62 changes: 60 additions & 2 deletions internal/service/quicksight/data_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ func TestAccQuickSightDataSet_logicalTableMap(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.alias", "Group1"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.physical_table_id", rId),
resource.TestCheckResourceAttr(resourceName, "output_columns.#", "1"),
resource.TestCheckResourceAttr(resourceName, "output_columns.0.name", "Column1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataSetConfigUpdateLogicalTableMap(rId, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSetExists(ctx, resourceName, &dataSet),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.alias", "Group1"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logical_table_map.0.source.0.physical_table_id", rId),
resource.TestCheckResourceAttr(resourceName, "output_columns.#", "2"),
resource.TestCheckResourceAttr(resourceName, "output_columns.0.name", "Column1"),
resource.TestCheckResourceAttr(resourceName, "output_columns.1.name", "Column2"),
),
},
{
Expand Down Expand Up @@ -657,9 +677,38 @@ resource "aws_quicksight_data_set" "test" {
name = "Column1"
type = "STRING"
}
upload_settings {
format = "JSON"
upload_settings {}
}
}
logical_table_map {
logical_table_map_id = %[1]q
alias = "Group1"
source {
physical_table_id = %[1]q
}
}
}
`, rId, rName))
}

func testAccDataSetConfigUpdateLogicalTableMap(rId, rName 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 {}
}
}
logical_table_map {
Expand All @@ -668,6 +717,15 @@ resource "aws_quicksight_data_set" "test" {
source {
physical_table_id = %[1]q
}
data_transforms {
create_columns_operation {
columns {
column_id = "Column2"
column_name = "Column2"
expression = "Column1"
}
}
}
}
}
`, rId, rName))
Expand Down
Loading