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

F/aws fsx windows file system: Support Support updating throughput_capacity and Storage_Capacity #15582

Merged
37 changes: 37 additions & 0 deletions aws/fsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ func refreshFsxFileSystemLifecycle(conn *fsx.FSx, id string) resource.StateRefre
}
}

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

if isAWSErr(err, fsx.ErrCodeFileSystemNotFound, "") {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

if filesystem == nil {
return nil, "", nil
}

return filesystem, aws.StringValue(filesystem.AdministrativeActions[0].Status), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is missing a length check on AdministrativeActions, which can cause a panic. Created followup issue: #16440

}
}

func waitForFsxFileSystemCreation(conn *fsx.FSx, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{fsx.FileSystemLifecycleCreating},
Expand Down Expand Up @@ -89,3 +109,20 @@ func waitForFsxFileSystemUpdate(conn *fsx.FSx, id string, timeout time.Duration)

return err
}

func waitForFsxFileSystemUpdateOptimizing(conn *fsx.FSx, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{fsx.StatusInProgress},
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like FSx also uses a PENDING status before it goes in progress. Created followup issue: #16440

Target: []string{
fsx.StatusCompleted,
fsx.StatusUpdatedOptimizing,
},
Refresh: refreshFsxFileSystemLifecycleOptimizing(conn, id),
Timeout: timeout,
Delay: 30 * time.Second,
}

_, err := stateConf.WaitForState()

return err
}
16 changes: 14 additions & 2 deletions aws/resource_aws_fsx_windows_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
"storage_capacity": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(32, 65536),
},
"subnet_ids": {
Expand All @@ -160,7 +159,6 @@ func resourceAwsFsxWindowsFileSystem() *schema.Resource {
"throughput_capacity": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(8, 2048),
},
"vpc_id": {
Expand Down Expand Up @@ -309,6 +307,16 @@ func resourceAwsFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interfac
requestUpdate = true
}

if d.HasChange("throughput_capacity") {
input.WindowsConfiguration.ThroughputCapacity = aws.Int64(int64(d.Get("throughput_capacity").(int)))
requestUpdate = true
}

if d.HasChange("storage_capacity") {
input.StorageCapacity = aws.Int64(int64(d.Get("storage_capacity").(int)))
requestUpdate = true
}

if d.HasChange("daily_automatic_backup_start_time") {
input.WindowsConfiguration.DailyAutomaticBackupStartTime = aws.String(d.Get("daily_automatic_backup_start_time").(string))
requestUpdate = true
Expand All @@ -329,6 +337,10 @@ func resourceAwsFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interfac
if err != nil {
return fmt.Errorf("error updating FSX File System (%s): %s", 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)
}
}

return resourceAwsFsxWindowsFileSystemRead(d, meta)
Expand Down
14 changes: 7 additions & 7 deletions aws/resource_aws_fsx_windows_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,10 @@ func TestAccAWSFsxWindowsFileSystem_StorageCapacity(t *testing.T) {
CheckDestroy: testAccCheckFsxWindowsFileSystemDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsFsxWindowsFileSystemConfigStorageCapacity(33),
Config: testAccAwsFsxWindowsFileSystemConfigStorageCapacity(32),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem1),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "33"),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "32"),
),
},
{
Expand All @@ -554,11 +554,11 @@ func TestAccAWSFsxWindowsFileSystem_StorageCapacity(t *testing.T) {
},
},
{
Config: testAccAwsFsxWindowsFileSystemConfigStorageCapacity(34),
Config: testAccAwsFsxWindowsFileSystemConfigStorageCapacity(36),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem2),
testAccCheckFsxWindowsFileSystemRecreated(&filesystem1, &filesystem2),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "34"),
testAccCheckFsxWindowsFileSystemNotRecreated(&filesystem1, &filesystem2),
resource.TestCheckResourceAttr(resourceName, "storage_capacity", "36"),
),
},
},
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestAccAWSFsxWindowsFileSystem_ThroughputCapacity(t *testing.T) {
Config: testAccAwsFsxWindowsFileSystemConfigThroughputCapacity(32),
Check: resource.ComposeTestCheckFunc(
testAccCheckFsxWindowsFileSystemExists(resourceName, &filesystem2),
testAccCheckFsxWindowsFileSystemRecreated(&filesystem1, &filesystem2),
testAccCheckFsxWindowsFileSystemNotRecreated(&filesystem1, &filesystem2),
resource.TestCheckResourceAttr(resourceName, "throughput_capacity", "32"),
),
},
Expand Down Expand Up @@ -1000,7 +1000,7 @@ resource "aws_fsx_windows_file_system" "test" {
skip_final_backup = true
storage_capacity = %[1]d
subnet_ids = [aws_subnet.test1.id]
throughput_capacity = 8
throughput_capacity = 16
}
`, storageCapacity)
}
Expand Down