Skip to content

Commit

Permalink
New Resources: aws_fsx_lustre_file_system and aws_fsx_windows_file_sy…
Browse files Browse the repository at this point in the history
…stem

Reference: #7035
Reference: #7074

Builds on #7074 with the following changes:

- Split into two separate resources (`aws_fsx_lustre_file_system` and `aws_fsx_windows_file_system`) to simplify practitioner configuration (e.g. lose the required configuration blocks), ease maintenance for resource logic and single file system arguments (e.g. `kms_key_id` only for Windows), and enhance validations (e.g. `storage_capacity` differences between file systems)
- Add covering acceptance testing with updates/force new for all arguments
- Better alignment with API naming for some arguments (e.g. changing `capacity` into `storage_capacity` to remove ambiguity with `throughput_capacity`)
- Implement [resource Customizable Timeouts](https://www.terraform.io/docs/extend/resources/retries-and-customizable-timeouts.html)
- Implement `skip_final_backup` argument for Windows
- Implement `network_interface_ids`, `owner_id`, and `vpc_id` attributes
- Augment resource documentation with additional notes found in [API reference](https://docs.aws.amazon.com/fsx/latest/APIReference/) and clarify `security_group_ids` import behavior

Output from acceptance testing:

```
--- PASS: TestAccAWSFsxLustreFileSystem_Tags (458.62s)
--- PASS: TestAccAWSFsxLustreFileSystem_basic (526.79s)
--- PASS: TestAccAWSFsxLustreFileSystem_disappears (564.58s)
--- PASS: TestAccAWSFsxLustreFileSystem_WeeklyMaintenanceStartTime (697.83s)
--- PASS: TestAccAWSFsxLustreFileSystem_StorageCapacity (940.13s)
--- PASS: TestAccAWSFsxLustreFileSystem_SecurityGroupIds (1074.08s)
--- PASS: TestAccAWSFsxLustreFileSystem_ImportedFileChunkSize (1276.18s)
--- PASS: TestAccAWSFsxLustreFileSystem_ImportPath (1322.13s)
--- PASS: TestAccAWSFsxLustreFileSystem_ExportPath (1338.75s)

--- PASS: TestAccAWSFsxWindowsFileSystem_Tags (2256.64s)
--- PASS: TestAccAWSFsxWindowsFileSystem_WeeklyMaintenanceStartTime (2346.44s)
--- PASS: TestAccAWSFsxWindowsFileSystem_basic (2404.35s)
--- PASS: TestAccAWSFsxWindowsFileSystem_disappears (2412.10s)
--- PASS: TestAccAWSFsxWindowsFileSystem_AutomaticBackupRetentionDays (2514.61s)
--- PASS: TestAccAWSFsxWindowsFileSystem_DailyAutomaticBackupStartTime (2849.43s)
--- PASS: TestAccAWSFsxWindowsFileSystem_SelfManagedActiveDirectory (2850.64s)
--- PASS: TestAccAWSFsxWindowsFileSystem_ThroughputCapacity (3292.44s)
--- PASS: TestAccAWSFsxWindowsFileSystem_SecurityGroupIds (3609.37s)
--- PASS: TestAccAWSFsxWindowsFileSystem_KmsKeyId (3977.10s)
--- PASS: TestAccAWSFsxWindowsFileSystem_StorageCapacity (4026.67s)
--- PASS: TestAccAWSFsxWindowsFileSystem_CopyTagsToBackups (4389.57s)
```
  • Loading branch information
bflad committed Aug 14, 2019
1 parent 170648a commit 446a22a
Show file tree
Hide file tree
Showing 14 changed files with 2,514 additions and 1,127 deletions.
77 changes: 77 additions & 0 deletions aws/fsx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package aws

import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/fsx"
"github.com/hashicorp/terraform/helper/resource"
)

func describeFsxFileSystem(conn *fsx.FSx, id string) (*fsx.FileSystem, error) {
input := &fsx.DescribeFileSystemsInput{
FileSystemIds: []*string{aws.String(id)},
}
var filesystem *fsx.FileSystem

err := conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
for _, fs := range page.FileSystems {
if aws.StringValue(fs.FileSystemId) == id {
filesystem = fs
return false
}
}

return !lastPage
})

return filesystem, err
}

func refreshFsxFileSystemLifecycle(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.Lifecycle), nil
}
}

func waitForFsxFileSystemCreation(conn *fsx.FSx, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{fsx.FileSystemLifecycleCreating},
Target: []string{fsx.FileSystemLifecycleAvailable},
Refresh: refreshFsxFileSystemLifecycle(conn, id),
Timeout: timeout,
Delay: 30 * time.Second,
}

_, err := stateConf.WaitForState()

return err
}

func waitForFsxFileSystemDeletion(conn *fsx.FSx, id string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{fsx.FileSystemLifecycleAvailable, fsx.FileSystemLifecycleDeleting},
Target: []string{},
Refresh: refreshFsxFileSystemLifecycle(conn, id),
Timeout: timeout,
Delay: 30 * time.Second,
}

_, err := stateConf.WaitForState()

return err
}
3 changes: 2 additions & 1 deletion aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ func Provider() terraform.ResourceProvider {
"aws_emr_instance_group": resourceAwsEMRInstanceGroup(),
"aws_emr_security_configuration": resourceAwsEMRSecurityConfiguration(),
"aws_flow_log": resourceAwsFlowLog(),
"aws_fsx_file_system": resourceAwsFsxFileSystem(),
"aws_fsx_lustre_file_system": resourceAwsFsxLustreFileSystem(),
"aws_fsx_windows_file_system": resourceAwsFsxWindowsFileSystem(),
"aws_fms_admin_account": resourceAwsFmsAdminAccount(),
"aws_gamelift_alias": resourceAwsGameliftAlias(),
"aws_gamelift_build": resourceAwsGameliftBuild(),
Expand Down
Loading

0 comments on commit 446a22a

Please sign in to comment.