Skip to content

Commit

Permalink
Merge pull request #16472 from DrFaust92/r/storagegateway_gateway_ref…
Browse files Browse the repository at this point in the history
…actor

r/storagegateway_gateway - add missing `smb_active_directory_settings` arguments + validations.
  • Loading branch information
breathingdust authored Dec 2, 2020
2 parents 098d77e + e1f6b84 commit 7848157
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 95 deletions.
53 changes: 47 additions & 6 deletions aws/internal/service/storagegateway/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,55 @@ import (
)

const (
StoredIscsiVolumeStatusNotFound = "NotFound"
StoredIscsiVolumeStatusUnknown = "Unknown"
NfsFileShareStatusNotFound = "NotFound"
NfsFileShareStatusUnknown = "Unknown"
SmbFileShareStatusNotFound = "NotFound"
SmbFileShareStatusUnknown = "Unknown"
StorageGatewayGatewayStatusConnected = "GatewayConnected"
StoredIscsiVolumeStatusNotFound = "NotFound"
StoredIscsiVolumeStatusUnknown = "Unknown"
NfsFileShareStatusNotFound = "NotFound"
NfsFileShareStatusUnknown = "Unknown"
SmbFileShareStatusNotFound = "NotFound"
SmbFileShareStatusUnknown = "Unknown"
)

func StorageGatewayGatewayStatus(conn *storagegateway.StorageGateway, gatewayARN string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeGatewayInformationInput{
GatewayARN: aws.String(gatewayARN),
}

output, err := conn.DescribeGatewayInformation(input)

if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified gateway is not connected") {
return output, storagegateway.ErrorCodeGatewayNotConnected, nil
}

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

return output, StorageGatewayGatewayStatusConnected, nil
}
}

func StorageGatewayGatewayJoinDomainStatus(conn *storagegateway.StorageGateway, gatewayARN string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeSMBSettingsInput{
GatewayARN: aws.String(gatewayARN),
}

output, err := conn.DescribeSMBSettings(input)

if tfawserr.ErrMessageContains(err, storagegateway.ErrCodeInvalidGatewayRequestException, "The specified gateway is not connected") {
return output, storagegateway.ActiveDirectoryStatusUnknownError, nil
}

if err != nil {
return output, storagegateway.ActiveDirectoryStatusUnknownError, err
}

return output, aws.StringValue(output.ActiveDirectoryStatus), nil
}
}

// StoredIscsiVolumeStatus fetches the Volume and its Status
func StoredIscsiVolumeStatus(conn *storagegateway.StorageGateway, volumeARN string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
Expand Down
50 changes: 45 additions & 5 deletions aws/internal/service/storagegateway/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,53 @@ import (
)

const (
StoredIscsiVolumeAvailableTimeout = 5 * time.Minute
NfsFileShareAvailableDelay = 5 * time.Second
NfsFileShareDeletedDelay = 5 * time.Second
SmbFileShareAvailableDelay = 5 * time.Second
SmbFileShareDeletedDelay = 5 * time.Second
StorageGatewayGatewayConnectedMinTimeout = 10 * time.Second
StorageGatewayGatewayConnectedContinuousTargetOccurence = 6
StorageGatewayGatewayJoinDomainJoinedTimeout = 5 * time.Minute
StoredIscsiVolumeAvailableTimeout = 5 * time.Minute
NfsFileShareAvailableDelay = 5 * time.Second
NfsFileShareDeletedDelay = 5 * time.Second
SmbFileShareAvailableDelay = 5 * time.Second
SmbFileShareDeletedDelay = 5 * time.Second
)

func StorageGatewayGatewayConnected(conn *storagegateway.StorageGateway, gatewayARN string, timeout time.Duration) (*storagegateway.DescribeGatewayInformationOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{storagegateway.ErrorCodeGatewayNotConnected},
Target: []string{StorageGatewayGatewayStatusConnected},
Refresh: StorageGatewayGatewayStatus(conn, gatewayARN),
Timeout: timeout,
MinTimeout: StorageGatewayGatewayConnectedMinTimeout,
ContinuousTargetOccurence: StorageGatewayGatewayConnectedContinuousTargetOccurence, // Gateway activations can take a few seconds and can trigger a reboot of the Gateway
}

outputRaw, err := stateConf.WaitForState()

switch output := outputRaw.(type) {
case *storagegateway.DescribeGatewayInformationOutput:
return output, err
default:
return nil, err
}
}

func StorageGatewayGatewayJoinDomainJoined(conn *storagegateway.StorageGateway, volumeARN string) (*storagegateway.DescribeSMBSettingsOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{storagegateway.ActiveDirectoryStatusJoining},
Target: []string{storagegateway.ActiveDirectoryStatusJoined},
Refresh: StorageGatewayGatewayJoinDomainStatus(conn, volumeARN),
Timeout: StorageGatewayGatewayJoinDomainJoinedTimeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}

// StoredIscsiVolumeAvailable waits for a StoredIscsiVolume to return Available
func StoredIscsiVolumeAvailable(conn *storagegateway.StorageGateway, volumeARN string) (*storagegateway.DescribeStorediSCSIVolumesOutput, error) {
stateConf := &resource.StateChangeConf{
Expand Down
Loading

0 comments on commit 7848157

Please sign in to comment.