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_gateway - add missing smb_active_directory_settings arguments + validations. #16472

Merged
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