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

fix resourceDashboardUpdate #34227

Merged
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
11 changes: 11 additions & 0 deletions .changelog/34227.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:bug
resource/aws_quicksight_dashboard: Fix failure when updating a dashboard takes a while
```

```release-note:bug
resource/aws_quicksight_template: Fix "a number is required" errors when state contains an empty string
```

```release-note:bug
resource/aws_quicksight_template: Fix "Invalid address to set" errors
```
20 changes: 13 additions & 7 deletions internal/service/quicksight/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func ResourceDashboard() *schema.Resource {
}

const (
ResNameDashboard = "Dashboard"
ResNameDashboard = "Dashboard"
DashboardLatestVersion int64 = -1
)

func resourceDashboardCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down Expand Up @@ -203,7 +204,7 @@ func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta int
return diag.FromErr(err)
}

out, err := FindDashboardByID(ctx, conn, d.Id())
out, err := FindDashboardByID(ctx, conn, d.Id(), DashboardLatestVersion)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] QuickSight Dashboard (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -297,14 +298,15 @@ func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta i
return create.DiagError(names.QuickSight, create.ErrActionUpdating, ResNameDashboard, d.Id(), err)
}

if _, err := waitDashboardUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
updatedVersionNumber := extractVersionFromARN(aws.StringValue(out.VersionArn))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of how extractVersionFromARN is used here, it should return int64 instead of *int64. That way, the parameter will not need to be dereferenced when passed to waitDashboardUpdated. When setting the parameter on publishVersion, use aws.Int64(updatedVersionNumber)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have addressed this 👍

if _, err := waitDashboardUpdated(ctx, conn, d.Id(), updatedVersionNumber, d.Timeout(schema.TimeoutUpdate)); err != nil {
return create.DiagError(names.QuickSight, create.ErrActionWaitingForUpdate, ResNameDashboard, d.Id(), err)
}

publishVersion := &quicksight.UpdateDashboardPublishedVersionInput{
AwsAccountId: aws.String(awsAccountId),
DashboardId: aws.String(dashboardId),
VersionNumber: extractVersionFromARN(aws.StringValue(out.VersionArn)),
VersionNumber: aws.Int64(updatedVersionNumber),
}
_, err = conn.UpdateDashboardPublishedVersionWithContext(ctx, publishVersion)
if err != nil {
Expand Down Expand Up @@ -367,7 +369,8 @@ func resourceDashboardDelete(ctx context.Context, d *schema.ResourceData, meta i
return nil
}

func FindDashboardByID(ctx context.Context, conn *quicksight.QuickSight, id string) (*quicksight.Dashboard, error) {
// Pass version as DashboardLatestVersion for latest published version, or specify a specific version if required
func FindDashboardByID(ctx context.Context, conn *quicksight.QuickSight, id string, version int64) (*quicksight.Dashboard, error) {
awsAccountId, dashboardId, err := ParseDashboardId(id)
if err != nil {
return nil, err
Expand All @@ -377,6 +380,9 @@ func FindDashboardByID(ctx context.Context, conn *quicksight.QuickSight, id stri
AwsAccountId: aws.String(awsAccountId),
DashboardId: aws.String(dashboardId),
}
if version != DashboardLatestVersion {
descOpts.VersionNumber = aws.Int64(version)
}

out, err := conn.DescribeDashboardWithContext(ctx, descOpts)

Expand Down Expand Up @@ -410,7 +416,7 @@ func createDashboardId(awsAccountID, dashboardId string) string {
return fmt.Sprintf("%s,%s", awsAccountID, dashboardId)
}

func extractVersionFromARN(arn string) *int64 {
func extractVersionFromARN(arn string) int64 {
version, _ := strconv.Atoi(arn[strings.LastIndex(arn, "/")+1:])
return aws.Int64(int64(version))
return int64(version)
}
23 changes: 20 additions & 3 deletions internal/service/quicksight/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestAccQuickSightDashboard_updateVersionNumber(t *testing.T) {
ctx := acctest.Context(t)

var dashboard quicksight.Dashboard
var dashboardV1 quicksight.Dashboard
resourceName := "aws_quicksight_dashboard.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rNameUpdated := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand All @@ -151,11 +152,13 @@ func TestAccQuickSightDashboard_updateVersionNumber(t *testing.T) {
{
Config: testAccDashboardConfig_basic(rId, rNameUpdated),
Check: resource.ComposeTestCheckFunc(
testAccCheckDashboardExists(ctx, resourceName, &dashboard),
testAccCheckDashboardExists(ctx, resourceName, &dashboardV1),
resource.TestCheckResourceAttr(resourceName, "dashboard_id", rId),
resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated),
resource.TestCheckResourceAttr(resourceName, "status", quicksight.ResourceStatusCreationSuccessful),
resource.TestCheckResourceAttr(resourceName, "version_number", "2"),
testAccCheckDashboardVersionExists(ctx, resourceName, 1, &dashboardV1),
testAccCheckDashboardName(&dashboardV1, rName),
),
},
},
Expand Down Expand Up @@ -206,7 +209,7 @@ func testAccCheckDashboardDestroy(ctx context.Context) resource.TestCheckFunc {
continue
}

output, err := tfquicksight.FindDashboardByID(ctx, conn, rs.Primary.ID)
output, err := tfquicksight.FindDashboardByID(ctx, conn, rs.Primary.ID, tfquicksight.DashboardLatestVersion)
if err != nil {
if tfawserr.ErrCodeEquals(err, quicksight.ErrCodeResourceNotFoundException) {
return nil
Expand All @@ -224,6 +227,10 @@ func testAccCheckDashboardDestroy(ctx context.Context) resource.TestCheckFunc {
}

func testAccCheckDashboardExists(ctx context.Context, name string, dashboard *quicksight.Dashboard) resource.TestCheckFunc {
return testAccCheckDashboardVersionExists(ctx, name, tfquicksight.DashboardLatestVersion, dashboard)
}

func testAccCheckDashboardVersionExists(ctx context.Context, name string, version int64, dashboard *quicksight.Dashboard) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -235,7 +242,7 @@ func testAccCheckDashboardExists(ctx context.Context, name string, dashboard *qu
}

conn := acctest.Provider.Meta().(*conns.AWSClient).QuickSightConn(ctx)
output, err := tfquicksight.FindDashboardByID(ctx, conn, rs.Primary.ID)
output, err := tfquicksight.FindDashboardByID(ctx, conn, rs.Primary.ID, version)

if err != nil {
return create.Error(names.QuickSight, create.ErrActionCheckingExistence, tfquicksight.ResNameDashboard, rs.Primary.ID, err)
Expand All @@ -247,6 +254,16 @@ func testAccCheckDashboardExists(ctx context.Context, name string, dashboard *qu
}
}

func testAccCheckDashboardName(dashboard *quicksight.Dashboard, expectedName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *dashboard.Name != expectedName {
return create.Error(names.QuickSight, create.ErrActionChecking, tfquicksight.ResNameDashboard, *dashboard.Name, errors.New("value does not match expected"))
}

return nil
}
}

func testAccDashboardConfigBase(rId string, rName string) string {
return acctest.ConfigCompose(
testAccDataSetConfigBase(rId, rName),
Expand Down
14 changes: 9 additions & 5 deletions internal/service/quicksight/schema/template_sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,15 @@ func expandGridLayoutElement(tfMap map[string]interface{}) *quicksight.GridLayou
if v, ok := tfMap["row_span"].(int); ok && v != 0 {
layout.RowSpan = aws.Int64(int64(v))
}
if v, null, _ := nullable.Int(tfMap["column_index"].(string)).Value(); !null {
layout.ColumnIndex = aws.Int64(v)
if v, ok := tfMap["column_index"].(string); ok && v != "" {
if i, null, _ := nullable.Int(v).Value(); !null {
layout.ColumnIndex = aws.Int64(i)
}
}
if v, null, _ := nullable.Int(tfMap["row_index"].(string)).Value(); !null {
layout.RowIndex = aws.Int64(v)
if v, ok := tfMap["row_index"].(string); ok && v != "" {
if i, null, _ := nullable.Int(v).Value(); !null {
layout.RowIndex = aws.Int64(i)
}
}

return layout
Expand Down Expand Up @@ -1739,7 +1743,7 @@ func flattenFreeFormLayoutCanvasSizeOptions(apiObject *quicksight.FreeFormLayout

tfMap := map[string]interface{}{}
if apiObject.ScreenCanvasSizeOptions != nil {
tfMap["canvas_size_options"] = flattenFreeFormLayoutScreenCanvasSizeOptions(apiObject.ScreenCanvasSizeOptions)
tfMap["screen_canvas_size_options"] = flattenFreeFormLayoutScreenCanvasSizeOptions(apiObject.ScreenCanvasSizeOptions)
}

return []interface{}{tfMap}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/quicksight/schema/visual_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ func flattenTableFieldOption(apiObject []*quicksight.TableFieldOption) []interfa
tfMap["url_styling"] = flattenTableFieldURLConfiguration(config.URLStyling)
}
if config.Visibility != nil {
tfMap["visbility"] = aws.StringValue(config.Visibility)
tfMap["visibility"] = aws.StringValue(config.Visibility)
}
if config.Width != nil {
tfMap["width"] = aws.StringValue(config.Width)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/quicksight/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func statusTemplate(ctx context.Context, conn *quicksight.QuickSight, id string)
}

// Fetch Dashboard status
func statusDashboard(ctx context.Context, conn *quicksight.QuickSight, id string) retry.StateRefreshFunc {
func statusDashboard(ctx context.Context, conn *quicksight.QuickSight, id string, version int64) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
out, err := FindDashboardByID(ctx, conn, id)
out, err := FindDashboardByID(ctx, conn, id, version)
if tfresource.NotFound(err) {
return nil, "", nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/service/quicksight/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func waitDashboardCreated(ctx context.Context, conn *quicksight.QuickSight, id s
stateConf := &retry.StateChangeConf{
Pending: []string{quicksight.ResourceStatusCreationInProgress},
Target: []string{quicksight.ResourceStatusCreationSuccessful},
Refresh: statusDashboard(ctx, conn, id),
Refresh: statusDashboard(ctx, conn, id, DashboardLatestVersion),
Timeout: timeout,
NotFoundChecks: 20,
ContinuousTargetOccurence: 2,
Expand Down Expand Up @@ -161,11 +161,11 @@ func waitDashboardCreated(ctx context.Context, conn *quicksight.QuickSight, id s
return nil, err
}

func waitDashboardUpdated(ctx context.Context, conn *quicksight.QuickSight, id string, timeout time.Duration) (*quicksight.Dashboard, error) {
func waitDashboardUpdated(ctx context.Context, conn *quicksight.QuickSight, id string, version int64, timeout time.Duration) (*quicksight.Dashboard, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{quicksight.ResourceStatusUpdateInProgress, quicksight.ResourceStatusCreationInProgress},
Target: []string{quicksight.ResourceStatusUpdateSuccessful, quicksight.ResourceStatusCreationSuccessful},
Refresh: statusDashboard(ctx, conn, id),
Refresh: statusDashboard(ctx, conn, id, version),
Timeout: timeout,
NotFoundChecks: 20,
ContinuousTargetOccurence: 2,
Expand Down
Loading