Skip to content

Commit

Permalink
resource/aws_efs_file_system: Add attributes and refactor to use wait…
Browse files Browse the repository at this point in the history
…er package (#17969)

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSEFSFileSystem_kmsConfigurationWithoutEncryption (15.26s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy (29.48s)
--- PASS: TestAccAWSEFSFileSystem_disappears (37.95s)
--- PASS: TestAccAWSEFSFileSystem_kmsKey (54.93s)
--- PASS: TestAccAWSEFSFileSystem_ThroughputMode (65.88s)
--- PASS: TestAccAWSEFSFileSystem_basic (83.23s)
--- PASS: TestAccAWSEFSFileSystem_pagedTags (85.76s)
--- PASS: TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps (94.41s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_removal (96.71s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_update (107.04s)
--- PASS: TestAccAWSEFSFileSystem_tags (142.76s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSEFSFileSystem_kmsConfigurationWithoutEncryption (19.51s)
--- PASS: TestAccAWSEFSFileSystem_pagedTags (58.12s)
--- PASS: TestAccAWSEFSFileSystem_kmsKey (64.15s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy (67.15s)
--- PASS: TestAccAWSEFSFileSystem_disappears (85.41s)
--- PASS: TestAccAWSEFSFileSystem_basic (95.51s)
--- PASS: TestAccAWSEFSFileSystem_ThroughputMode (101.41s)
--- PASS: TestAccAWSEFSFileSystem_ProvisionedThroughputInMibps (103.19s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_update (105.87s)
--- PASS: TestAccAWSEFSFileSystem_tags (149.67s)
--- PASS: TestAccAWSEFSFileSystem_lifecyclePolicy_removal (151.51s)
```
  • Loading branch information
DrFaust92 authored Mar 26, 2021
1 parent 344e9bc commit 79998b1
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .changelog/17969.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_efs_file_system: Add `number_of_mount_targets`, `size_in_bytes` and `owner_id` attributes
```
23 changes: 23 additions & 0 deletions aws/internal/service/efs/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,26 @@ func AccessPointLifeCycleState(conn *efs.EFS, accessPointId string) resource.Sta
return mt, aws.StringValue(mt.LifeCycleState), nil
}
}

// FileSystemLifeCycleState fetches the Access Point and its LifecycleState
func FileSystemLifeCycleState(conn *efs.EFS, fileSystemID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &efs.DescribeFileSystemsInput{
FileSystemId: aws.String(fileSystemID),
}

output, err := conn.DescribeFileSystems(input)

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

if output == nil || len(output.FileSystems) == 0 || output.FileSystems[0] == nil {
return nil, "", nil
}

mt := output.FileSystems[0]

return mt, aws.StringValue(mt.LifeCycleState), nil
}
}
50 changes: 48 additions & 2 deletions aws/internal/service/efs/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import (

const (
// Maximum amount of time to wait for an Operation to return Success
AccessPointCreatedTimeout = 10 * time.Minute
AccessPointDeletedTimeout = 10 * time.Minute
AccessPointCreatedTimeout = 10 * time.Minute
AccessPointDeletedTimeout = 10 * time.Minute
FileSystemAvailableTimeout = 10 * time.Minute
FileSystemAvailableDelayTimeout = 2 * time.Second
FileSystemAvailableMinTimeout = 3 * time.Second
FileSystemDeletedTimeout = 10 * time.Minute
FileSystemDeletedDelayTimeout = 2 * time.Second
FileSystemDeletedMinTimeout = 3 * time.Second
)

// AccessPointCreated waits for an Operation to return Success
Expand Down Expand Up @@ -48,3 +54,43 @@ func AccessPointDeleted(conn *efs.EFS, accessPointId string) (*efs.AccessPointDe

return nil, err
}

// FileSystemAvailable waits for an Operation to return Available
func FileSystemAvailable(conn *efs.EFS, fileSystemID string) (*efs.FileSystemDescription, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{efs.LifeCycleStateCreating, efs.LifeCycleStateUpdating},
Target: []string{efs.LifeCycleStateAvailable},
Refresh: FileSystemLifeCycleState(conn, fileSystemID),
Timeout: FileSystemAvailableTimeout,
Delay: FileSystemAvailableDelayTimeout,
MinTimeout: FileSystemAvailableMinTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*efs.FileSystemDescription); ok {
return output, err
}

return nil, err
}

// FileSystemDeleted waits for an Operation to return Deleted
func FileSystemDeleted(conn *efs.EFS, fileSystemID string) (*efs.FileSystemDescription, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{efs.LifeCycleStateAvailable, efs.LifeCycleStateDeleting},
Target: []string{},
Refresh: FileSystemLifeCycleState(conn, fileSystemID),
Timeout: FileSystemDeletedTimeout,
Delay: FileSystemDeletedDelayTimeout,
MinTimeout: FileSystemDeletedMinTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*efs.FileSystemDescription); ok {
return output, err
}

return nil, err
}
Loading

0 comments on commit 79998b1

Please sign in to comment.