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

r/aws_quicksight: convert calculated_fields to set type #33040

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .changelog/33040.txt
Original file line number Diff line number Diff line change
@@ -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
```
123 changes: 123 additions & 0 deletions internal/service/quicksight/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
16 changes: 1 addition & 15 deletions internal/service/quicksight/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -134,10 +133,7 @@ func ResourceDashboard() *schema.Resource {
}
},

CustomizeDiff: customdiff.All(
refreshOutputsDiff,
verify.SetTagsDiff,
),
CustomizeDiff: verify.SetTagsDiff,
}
}

Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions internal/service/quicksight/schema/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/quicksight/schema/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/service/quicksight/schema/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down