Skip to content

Commit

Permalink
Merge pull request #16340 from DrFaust92/r/storagegateway_nfs_file_sh…
Browse files Browse the repository at this point in the history
…are_notif

r/storagegateway_nfs_file_share - add support for `notification_policy` + validations
  • Loading branch information
breathingdust authored Nov 23, 2020
2 parents 71ca835 + b2f6aaa commit fbf325f
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 87 deletions.
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"},
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

0 comments on commit fbf325f

Please sign in to comment.