Skip to content

Commit

Permalink
resource/aws_fsx_windows_file_system: Prevent potential panics, unexp…
Browse files Browse the repository at this point in the history
…ected errors, and use correct operation timeout on update

Reference: https://docs.aws.amazon.com/fsx/latest/APIReference/API_AdministrativeAction.html
Reference: #16440

Output from acceptance testing:

```
Pending
```
  • Loading branch information
bflad committed Nov 30, 2020
1 parent e317710 commit 7d13105
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
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

0 comments on commit 7d13105

Please # to comment.