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

r/efs_file_system - add attributes + refactor to use waiter package #17969

Merged
merged 10 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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