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

resource/aws_fsx_windows_file_system: Prevent potential panics, unexpected errors, and use correct operation timeout on update #16488

Merged
merged 1 commit into from
Dec 1, 2020
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
23 changes: 18 additions & 5 deletions aws/fsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func refreshFsxFileSystemLifecycle(conn *fsx.FSx, id string) resource.StateRefre
}
}

func refreshFsxFileSystemLifecycleOptimizing(conn *fsx.FSx, id string) resource.StateRefreshFunc {
func refreshFsxFileSystemAdministrativeActionsStatusFileSystemUpdate(conn *fsx.FSx, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
filesystem, err := describeFsxFileSystem(conn, id)

Expand All @@ -64,7 +64,17 @@ func refreshFsxFileSystemLifecycleOptimizing(conn *fsx.FSx, id string) resource.
return nil, "", nil
}

return filesystem, aws.StringValue(filesystem.AdministrativeActions[0].Status), nil
for _, administrativeAction := range filesystem.AdministrativeActions {
if administrativeAction == nil {
continue
}

if aws.StringValue(administrativeAction.AdministrativeActionType) == fsx.AdministrativeActionTypeFileSystemUpdate {
return filesystem, aws.StringValue(administrativeAction.Status), nil
}
}

return filesystem, fsx.StatusCompleted, nil
}
}

Expand Down Expand Up @@ -110,14 +120,17 @@ func waitForFsxFileSystemUpdate(conn *fsx.FSx, id string, timeout time.Duration)
return err
}

func waitForFsxFileSystemUpdateOptimizing(conn *fsx.FSx, id string, timeout time.Duration) error {
func waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn *fsx.FSx, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{fsx.StatusInProgress},
Pending: []string{
fsx.StatusInProgress,
fsx.StatusPending,
},
Target: []string{
fsx.StatusCompleted,
fsx.StatusUpdatedOptimizing,
},
Refresh: refreshFsxFileSystemLifecycleOptimizing(conn, id),
Refresh: refreshFsxFileSystemAdministrativeActionsStatusFileSystemUpdate(conn, id),
Timeout: timeout,
Delay: 30 * time.Second,
}
Expand Down
8 changes: 5 additions & 3 deletions aws/resource_aws_fsx_windows_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(45 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(45 * time.Minute),
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -334,12 +335,13 @@ func resourceAwsFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interfac

if requestUpdate {
_, err := conn.UpdateFileSystem(input)

if err != nil {
return fmt.Errorf("error updating FSX File System (%s): %s", d.Id(), err)
return fmt.Errorf("error updating FSx Windows File System (%s): %w", d.Id(), err)
}

if err := waitForFsxFileSystemUpdateOptimizing(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return fmt.Errorf("Error waiting for filesystem (%s) to become available: %w", d.Id(), err)
if err := waitForFsxFileSystemUpdateAdministrativeActionsStatusFileSystemUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("error waiting for FSx Windows File System (%s) update: %w", d.Id(), err)
}
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/fsx_windows_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ configuration options:

* `create` - (Default `45m`) How long to wait for the file system to be created.
* `delete` - (Default `30m`) How long to wait for the file system to be deleted.
* `update` - (Default `45m`) How long to wait for the file system to be updated.

## Import

Expand Down