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/storagegateway_nfs_file_share - add support for notification_policy + validations #16340

Merged
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
30 changes: 30 additions & 0 deletions aws/internal/service/storagegateway/waiter/status.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package waiter

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/storagegateway"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
Expand All @@ -10,6 +13,8 @@ import (
const (
StoredIscsiVolumeStatusNotFound = "NotFound"
StoredIscsiVolumeStatusUnknown = "Unknown"
NfsFileShareStatusNotFound = "NotFound"
NfsFileShareStatusUnknown = "Unknown"
)

// StoredIscsiVolumeStatus fetches the Volume and its Status
Expand Down Expand Up @@ -37,3 +42,28 @@ func StoredIscsiVolumeStatus(conn *storagegateway.StorageGateway, volumeARN stri
return output, aws.StringValue(output.StorediSCSIVolumes[0].VolumeStatus), nil
}
}

func NfsFileShareStatus(conn *storagegateway.StorageGateway, fileShareArn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeNFSFileSharesInput{
FileShareARNList: []*string{aws.String(fileShareArn)},
}

log.Printf("[DEBUG] Reading Storage Gateway NFS File Share: %s", input)
output, err := conn.DescribeNFSFileShares(input)
if err != nil {
if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified file share was not found.") {
return nil, NfsFileShareStatusNotFound, nil
}
return nil, NfsFileShareStatusUnknown, fmt.Errorf("error reading Storage Gateway NFS File Share: %w", err)
}

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

fileshare := output.NFSFileShareInfoList[0]

return fileshare, aws.StringValue(fileshare.FileShareStatus), nil
}
}
40 changes: 40 additions & 0 deletions aws/internal/service/storagegateway/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

const (
StoredIscsiVolumeAvailableTimeout = 5 * time.Minute
NfsFileShareAvailableDelay = 5 * time.Second
NfsFileShareDeletedDelay = 5 * time.Second
)

// StoredIscsiVolumeAvailable waits for a StoredIscsiVolume to return Available
Expand All @@ -28,3 +30,41 @@ func StoredIscsiVolumeAvailable(conn *storagegateway.StorageGateway, volumeARN s

return nil, err
}

// NfsFileShareAvailable waits for a NFS File Share to return Available
func NfsFileShareAvailable(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"BOOTSTRAPPING", "CREATING", "RESTORING", "UPDATING"},
Target: []string{"AVAILABLE"},
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

Define these as constants?

Refresh: NfsFileShareStatus(conn, fileShareArn),
Timeout: timeout,
Delay: NfsFileShareAvailableDelay,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

func NfsFileShareDeleted(conn *storagegateway.StorageGateway, fileShareArn string, timeout time.Duration) (*storagegateway.NFSFileShareInfo, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"AVAILABLE", "DELETING", "FORCE_DELETING"},
Target: []string{},
Refresh: NfsFileShareStatus(conn, fileShareArn),
Timeout: timeout,
Delay: NfsFileShareDeletedDelay,
NotFoundChecks: 1,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}
Loading