From af86bac78b2d3afb3984f8226577a716cbfd29a3 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 16 Aug 2023 10:19:20 -0400 Subject: [PATCH 1/3] r/aws_quicksight: convert calculated_fields to set type --- internal/service/quicksight/analysis_test.go | 123 ++++++++++++++++++ .../service/quicksight/schema/analysis.go | 4 +- .../service/quicksight/schema/dashboard.go | 4 +- .../service/quicksight/schema/template.go | 6 +- 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/internal/service/quicksight/analysis_test.go b/internal/service/quicksight/analysis_test.go index a6ed8be3701..873fb257fdd 100644 --- a/internal/service/quicksight/analysis_test.go +++ b/internal/service/quicksight/analysis_test.go @@ -225,6 +225,52 @@ func TestAccQuickSightAnalysis_forceDelete(t *testing.T) { }) } +func TestAccQuickSightAnalysis_Definition_calculatedFields(t *testing.T) { + ctx := acctest.Context(t) + + var analysis quicksight.Analysis + resourceName := "aws_quicksight_analysis.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, quicksight.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAnalysisDestroy(ctx, false), + Steps: []resource.TestStep{ + { + Config: testAccAnalysisConfig_Definition_calculatedFields(rId, rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAnalysisExists(ctx, resourceName, &analysis), + resource.TestCheckResourceAttr(resourceName, "analysis_id", rId), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "status", quicksight.ResourceStatusCreationSuccessful), + resource.TestCheckResourceAttr(resourceName, "definition.#", "1"), + resource.TestCheckResourceAttr(resourceName, "definition.0.calculated_fields.#", "2"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "definition.0.calculated_fields.*", map[string]string{ + "data_set_identifier": "1", + "expression": "1", + "name": "test1", + }), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "definition.0.calculated_fields.*", map[string]string{ + "data_set_identifier": "1", + "expression": "2", + "name": "test2", + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAnalysisDestroy(ctx context.Context, forceDelete bool) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).QuickSightConn(ctx) @@ -612,3 +658,80 @@ resource "aws_quicksight_analysis" "test" { } `, rId, rName)) } + +func testAccAnalysisConfig_Definition_calculatedFields(rId, rName string) string { + return acctest.ConfigCompose( + testAccAnalysisConfigBase(rId, rName), + fmt.Sprintf(` +resource "aws_quicksight_analysis" "test" { + analysis_id = %[1]q + name = %[2]q + definition { + data_set_identifiers_declarations { + data_set_arn = aws_quicksight_data_set.test.arn + identifier = "1" + } + calculated_fields { + data_set_identifier = "1" + expression = "1" + name = "test1" + } + calculated_fields { + data_set_identifier = "1" + expression = "2" + name = "test2" + } + sheets { + title = "Test" + sheet_id = "Test1" + visuals { + custom_content_visual { + data_set_identifier = "1" + title { + format_text { + plain_text = "Test" + } + } + visual_id = "Test1" + } + } + visuals { + line_chart_visual { + visual_id = "LineChart" + title { + format_text { + plain_text = "Line Chart Test" + } + } + chart_configuration { + field_wells { + line_chart_aggregated_field_wells { + category { + categorical_dimension_field { + field_id = "1" + column { + data_set_identifier = "1" + column_name = "Column1" + } + } + } + values { + categorical_measure_field { + field_id = "2" + column { + data_set_identifier = "1" + column_name = "Column1" + } + aggregation_function = "COUNT" + } + } + } + } + } + } + } + } + } +} +`, rId, rName)) +} diff --git a/internal/service/quicksight/schema/analysis.go b/internal/service/quicksight/schema/analysis.go index c7f53e1a167..8bd04a73470 100644 --- a/internal/service/quicksight/schema/analysis.go +++ b/internal/service/quicksight/schema/analysis.go @@ -191,8 +191,8 @@ func ExpandAnalysisDefinition(tfList []interface{}) *quicksight.AnalysisDefiniti if v, ok := tfMap["analysis_defaults"].([]interface{}); ok && len(v) > 0 { definition.AnalysisDefaults = expandAnalysisDefaults(v) } - if v, ok := tfMap["calculated_fields"].([]interface{}); ok && len(v) > 0 { - definition.CalculatedFields = expandCalculatedFields(v) + if v, ok := tfMap["calculated_fields"].(*schema.Set); ok && v.Len() > 0 { + definition.CalculatedFields = expandCalculatedFields(v.List()) } if v, ok := tfMap["column_configurations"].([]interface{}); ok && len(v) > 0 { definition.ColumnConfigurations = expandColumnConfigurations(v) diff --git a/internal/service/quicksight/schema/dashboard.go b/internal/service/quicksight/schema/dashboard.go index d90845e53f2..b78e435db76 100644 --- a/internal/service/quicksight/schema/dashboard.go +++ b/internal/service/quicksight/schema/dashboard.go @@ -346,8 +346,8 @@ func ExpandDashboardDefinition(tfList []interface{}) *quicksight.DashboardVersio if v, ok := tfMap["analysis_defaults"].([]interface{}); ok && len(v) > 0 { definition.AnalysisDefaults = expandAnalysisDefaults(v) } - if v, ok := tfMap["calculated_fields"].([]interface{}); ok && len(v) > 0 { - definition.CalculatedFields = expandCalculatedFields(v) + if v, ok := tfMap["calculated_fields"].(*schema.Set); ok && v.Len() > 0 { + definition.CalculatedFields = expandCalculatedFields(v.List()) } if v, ok := tfMap["column_configurations"].([]interface{}); ok && len(v) > 0 { definition.ColumnConfigurations = expandColumnConfigurations(v) diff --git a/internal/service/quicksight/schema/template.go b/internal/service/quicksight/schema/template.go index d7d9c738d97..2c770018919 100644 --- a/internal/service/quicksight/schema/template.go +++ b/internal/service/quicksight/schema/template.go @@ -167,7 +167,7 @@ func aggregationFunctionSchema(required bool) *schema.Schema { func calculatedFieldsSchema() *schema.Schema { return &schema.Schema{ // https://docs.aws.amazon.com/quicksight/latest/APIReference/API_CalculatedField.html - Type: schema.TypeList, + Type: schema.TypeSet, MinItems: 1, MaxItems: 500, Optional: true, @@ -479,8 +479,8 @@ func ExpandTemplateDefinition(tfList []interface{}) *quicksight.TemplateVersionD if v, ok := tfMap["analysis_defaults"].([]interface{}); ok && len(v) > 0 { definition.AnalysisDefaults = expandAnalysisDefaults(v) } - if v, ok := tfMap["calculated_fields"].([]interface{}); ok && len(v) > 0 { - definition.CalculatedFields = expandCalculatedFields(v) + if v, ok := tfMap["calculated_fields"].(*schema.Set); ok && v.Len() > 0 { + definition.CalculatedFields = expandCalculatedFields(v.List()) } if v, ok := tfMap["column_configurations"].([]interface{}); ok && len(v) > 0 { definition.ColumnConfigurations = expandColumnConfigurations(v) From c9164a2af448c61d1e7cf53c0563a31fd02c5fc4 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 16 Aug 2023 10:55:08 -0400 Subject: [PATCH 2/3] r/aws_quicksight_dashboard: rm refresh outputs customize diff func --- internal/service/quicksight/dashboard.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/internal/service/quicksight/dashboard.go b/internal/service/quicksight/dashboard.go index 8bccb5b0a56..e8f9ba35300 100644 --- a/internal/service/quicksight/dashboard.go +++ b/internal/service/quicksight/dashboard.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go/service/quicksight" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -134,10 +133,7 @@ func ResourceDashboard() *schema.Resource { } }, - CustomizeDiff: customdiff.All( - refreshOutputsDiff, - verify.SetTagsDiff, - ), + CustomizeDiff: verify.SetTagsDiff, } } @@ -418,13 +414,3 @@ func extractVersionFromARN(arn string) *int64 { version, _ := strconv.Atoi(arn[strings.LastIndex(arn, "/")+1:]) return aws.Int64(int64(version)) } - -func refreshOutputsDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { - if diff.HasChanges("name", "definition", "source_entity", "theme_arn", "version_description", "parameters", "dashboard_publish_options") { - if err := diff.SetNewComputed("version_number"); err != nil { - return err - } - } - - return nil -} From 03d3271d158917f9d6f37ac6a3c8be40254beb0d Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 16 Aug 2023 11:04:32 -0400 Subject: [PATCH 3/3] chore: changelog --- .changelog/33040.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changelog/33040.txt diff --git a/.changelog/33040.txt b/.changelog/33040.txt new file mode 100644 index 00000000000..f2e1f5ab5b6 --- /dev/null +++ b/.changelog/33040.txt @@ -0,0 +1,9 @@ +```release-note:bug +resource/aws_quicksight_analysis: Convert `definition.*.calculated_fields` to a set type, preventing persistent differences +``` +```release-note:bug +resource/aws_quicksight_dashboard: Convert `definition.*.calculated_fields` to a set type, preventing persistent differences +``` +```release-note:bug +resource/aws_quicksight_template: Convert `definition.*.calculated_fields` to a set type, preventing persistent differences +```