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

[Bug]: Order lost in aws_quicksight_analysis causing endless plan updates due to ordering of calculated_fields blocks #32997

Closed
udidn opened this issue Aug 14, 2023 · 3 comments · Fixed by #33040
Assignees
Labels
bug Addresses a defect in current functionality. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/quicksight Issues and PRs that pertain to the quicksight service.
Milestone

Comments

@udidn
Copy link

udidn commented Aug 14, 2023

Terraform Core Version

1.5.3

AWS Provider Version

5.9.0

Affected Resource(s)

The calculated_fields block in aws_quicksight_analysis resource

Expected Behavior

When running multiple plans without changes to the Terraform configuration file, Terraform should detect no changes

Actual Behavior

When running multiple plans without changes to the Terraform configuration file, the outputs are updated on every plan due to reordering of the principals

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_quicksight_analysis" "test" {
  analysis_id = "test"
  name        = "test"
  theme_arn   = "arn:aws:quicksight::aws:theme/CLASSIC"

  definition {
    data_set_identifiers_declarations {
      identifier   = aws_quicksight_data_set.test.name
      data_set_arn = aws_quicksight_data_set.test.arn
    }

    calculated_fields {
      data_set_identifier = aws_quicksight_data_set.test.name
      expression          = "1"
      name                = "b_test"
    }

    calculated_fields {
      data_set_identifier = aws_quicksight_data_set.test.name
      expression          = "1"
      name                = "a_test"
    }

    analysis_defaults {
      default_new_sheet_configuration {
        interactive_layout_configuration {
          grid {
            canvas_size_options {
              screen_canvas_size_options {
                resize_option             = "FIXED"
                optimized_view_port_width = "1600px"
              }
            }
          }
        }
        sheet_content_type = "INTERACTIVE"
      }
    }
  }
}

Steps to Reproduce

  1. terraform apply
  2. terraform plan

Notice there's significance to the order of the calculated_fields blocks to recreate the issue.
It seems that QuickSight API consistently returns the calculated fields in ascending alphanumeric order:
So, int he above Terraform configuration, I intentionally ordered them reversed, so the issue can be recreated

Debug Output

No response

Panic Output

No response

Important Factoids

Note 1

Looks like the calculated_fields field's Type should be changed from TypeList to TypeSet (see here)

Note 2

The workaround for this issue is to make sure the calculated_fields blocks in the Terraform configuration file are sorted in ascending alphanumeric order.
This can be done by defining the calculated fields blocks in a list in locals and sort it bu name using sort function.
Example:

locals {
  calc_fields = [
    {
      calc_field_name = "b_test"
      expression      = "1"
    },
    {
      calc_field_name = "a_test"
      expression      = "1"
    }
  ]

  calc_fields_sorted = sort(local.calc_fields.*.calc_field_name)
}

resource "aws_quicksight_analysis" "test" {
  analysis_id = "test"
  name        = "test"
  theme_arn   = "arn:aws:quicksight::aws:theme/CLASSIC"

  definition {
    data_set_identifiers_declarations {
      identifier   = aws_quicksight_data_set.test.name
      data_set_arn = aws_quicksight_data_set.test.arn
    }

    dynamic "calculated_fields" {
      for_each = [for calc_field in local.calc_fields_sorted : calc_field]
      content {
        data_set_identifier = aws_quicksight_data_set.eks_insights.name
        expression          = lookup(element(local.calc_fields, index(local.calc_fields.*.calc_field_name, calculated_fields.value)), "expression", "")
        name                = calculated_fields.value
      }
    }

    analysis_defaults {
      default_new_sheet_configuration {
        interactive_layout_configuration {
          grid {
            canvas_size_options {
              screen_canvas_size_options {
                resize_option             = "FIXED"
                optimized_view_port_width = "1600px"
              }
            }
          }
        }
        sheet_content_type = "INTERACTIVE"
      }
    }
  }
}

Note 3

Since in QuickSight Analysis, the order of calculated fields isn't significant, the Terraform AWS Provider should ignore the order (although there's a workaround), and the user shouldn't be required to follow the QuickSight API order in the Terraform configuration file

References

There are similar GitHub issues in other QuickSight resources, such as #32645, #32991 and #32996

Would you like to implement a fix?

None

@udidn udidn added the bug Addresses a defect in current functionality. label Aug 14, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/quicksight Issues and PRs that pertain to the quicksight service. label Aug 14, 2023
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Aug 14, 2023
@justinretzolk justinretzolk added prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. and removed needs-triage Waiting for first response or review from a maintainer. labels Aug 14, 2023
@jar-b jar-b self-assigned this Aug 15, 2023
@github-actions github-actions bot added this to the v5.13.0 milestone Aug 17, 2023
@github-actions github-actions bot removed the bug Addresses a defect in current functionality. label Aug 18, 2023
@github-actions
Copy link

This functionality has been released in v5.13.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2023
@justinretzolk justinretzolk added the bug Addresses a defect in current functionality. label Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. service/quicksight Issues and PRs that pertain to the quicksight service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants