Skip to content

Commit

Permalink
Merge pull request #15582 from nikhil-goenka/f/aws_fsx_windows_file_s…
Browse files Browse the repository at this point in the history
…ystem

F/aws fsx windows file system: Support Support updating throughput_capacity and Storage_Capacity
  • Loading branch information
breathingdust authored Nov 23, 2020
2 parents fed1e4e + 1ee938b commit 1aec8ee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
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
}
}

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},
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

0 comments on commit 1aec8ee

Please sign in to comment.