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

Migrate Storage Gateway resources to AWS SDK V2 #38554

Merged
merged 42 commits into from
Jul 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9d06385
feat: regenerate client to v2
DanielRieske Jul 23, 2024
4bba24e
feat: migrate r/cache to sdkv2
DanielRieske Jul 23, 2024
bd171da
feat: migrate errors and find package to use sdkv2
DanielRieske Jul 23, 2024
394b8e9
Merge branch 'main' into f/migrate-storagegateway-sdkv2
DanielRieske Jul 26, 2024
68394b5
feat: migrate r/working_storage to SDKv2
DanielRieske Jul 26, 2024
ef9d002
feat: migrate r/cached_iscsi_volume to SDKv2
DanielRieske Jul 26, 2024
2773371
feat: migrate r/file_system_association to SDKv2
DanielRieske Jul 26, 2024
921fbf6
feat: migrate r/gateway to SDKv2
DanielRieske Jul 26, 2024
90183a0
feat: migrate r/nfs_file_share to SDKv2
DanielRieske Jul 26, 2024
443784c
feat: migrate r/smb_file_share to SDKv2
DanielRieske Jul 26, 2024
d1c250d
feat: migrate r/stored_iscsi_volume to SDKv2
DanielRieske Jul 26, 2024
4cd2069
feat: migrate r/upload_buffer to SDKv2
DanielRieske Jul 26, 2024
2f03d58
feat: migrate sweepers to SDKv2
DanielRieske Jul 26, 2024
bbff4e1
feat: migrate r/tape_pool to SDKv2
DanielRieske Jul 26, 2024
77f4b74
feat: migrate d/local_disk to SDKv2
DanielRieske Jul 26, 2024
07b9973
chore: reduce visibility
DanielRieske Jul 26, 2024
93b918f
feat: migrate `find` functions
DanielRieske Jul 26, 2024
2fe6a86
feat: migrate `status` functions to SDKv2
DanielRieske Jul 26, 2024
60ba820
feat: migrate `wait` functions to SDKv2
DanielRieske Jul 26, 2024
3755e47
chore: fix exports
DanielRieske Jul 26, 2024
5b18c41
fix: nil exception
DanielRieske Jul 26, 2024
c65609a
fix: fix `TestAccStorageGatewayTapePool_disappears`
DanielRieske Jul 26, 2024
b62214d
fix: spelling mistake in error message
DanielRieske Jul 26, 2024
0070e3f
fix: fix `TestAccStorageGatewayGateway_GatewayType_cached`
DanielRieske Jul 27, 2024
e8165f6
Merge branch 'main' into HEAD
ewbankkit Jul 27, 2024
703b349
Run 'go mod tidy'.
ewbankkit Jul 27, 2024
29fa298
Add 'findCacheByTwoPartKey'.
ewbankkit Jul 27, 2024
9077e79
Add 'findCachediSCSIVolumeByARN'.
ewbankkit Jul 28, 2024
6a680d5
r/aws_storagegateway_file_system_association: Cosmetics.
ewbankkit Jul 28, 2024
450041e
r/aws_storagegateway_gateway: Cosmetics.
ewbankkit Jul 29, 2024
4963ecb
d/aws_storagegateway_local_disk: Cosmetics.
ewbankkit Jul 29, 2024
ea20d02
r/aws_storagegateway_nfs_file_share: Cosmetics.
ewbankkit Jul 29, 2024
e2341a5
r/aws_storagegateway_smb_file_share: Cosmetics.
ewbankkit Jul 29, 2024
6d5d1a7
Add 'findStorediSCSIVolumeByARN'.
ewbankkit Jul 29, 2024
f3278ac
Add 'findTapePoolByARN'.
ewbankkit Jul 29, 2024
44c3acf
r/aws_storagegateway_upload_buffer: Cosmetics.
ewbankkit Jul 30, 2024
c524616
r/aws_storagegateway_working_storage: Add 'findWorkingStorageDiskIDBy…
ewbankkit Jul 31, 2024
2864aec
storagegateway: Tweak 'operationErrorCode'.
ewbankkit Jul 31, 2024
998c0d6
Merge branch 'main' into HEAD
ewbankkit Jul 31, 2024
4ab7daa
r/aws_storagegateway_file_system_association: Add configurable timeouts.
ewbankkit Jul 31, 2024
dafc14b
Fix semgrep 'dgryski.semgrep-go.errnilcheck.err-nil-check'.
ewbankkit Jul 31, 2024
ce32cd7
Fix 'TestAccStorageGatewayLocalDiskDataSource_diskNode' and 'TestAccS…
ewbankkit Jul 31, 2024
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
Prev Previous commit
Next Next commit
r/aws_storagegateway_gateway: Cosmetics.
ewbankkit committed Jul 29, 2024

Verified

This commit was signed with the committer’s verified signature.
ewbankkit Kit Ewbank
commit 450041e29ab339a17197779cb6ce2da3a0295757
6 changes: 5 additions & 1 deletion internal/service/storagegateway/errors.go
Original file line number Diff line number Diff line change
@@ -36,14 +36,18 @@ func operationErrorCode(err error) string {

// The API returns multiple responses for a missing gateway.
func isGatewayNotFoundErr(err error) bool {
if errs.IsAErrorMessageContains[*awstypes.InvalidGatewayRequestException](err, "The specified gateway was not found") {
if operationErrorCode(err) == operationErrCodeGatewayNotFound {
return true
}

if tfawserr.ErrCodeEquals(err, string(awstypes.ErrorCodeGatewayNotFound)) {
return true
}

if errs.IsAErrorMessageContains[*awstypes.InvalidGatewayRequestException](err, "The specified gateway was not found") {
return true
}

return false
}

4 changes: 2 additions & 2 deletions internal/service/storagegateway/file_system_association.go
Original file line number Diff line number Diff line change
@@ -289,7 +289,7 @@ func waitFileSystemAssociationAvailable(ctx context.Context, conn *storagegatewa
Target: []string{fileSystemAssociationStatusAvailable},
Refresh: statusFileSystemAssociation(ctx, conn, fileSystemArn),
Timeout: timeout,
Delay: fileSystemAssociationAvailableDelay,
Delay: 5 * time.Second,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
@@ -309,7 +309,7 @@ func waitFileSystemAssociationDeleted(ctx context.Context, conn *storagegateway.
Target: []string{},
Refresh: statusFileSystemAssociation(ctx, conn, fileSystemArn),
Timeout: timeout,
Delay: fileSystemAssociationDeletedDelay,
Delay: 5 * time.Second,
NotFoundChecks: 1,
}

26 changes: 0 additions & 26 deletions internal/service/storagegateway/find.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/storagegateway"
awstypes "github.com/aws/aws-sdk-go-v2/service/storagegateway/types"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
@@ -86,31 +85,6 @@ func findUploadBufferDisk(ctx context.Context, conn *storagegateway.Client, gate
return &result, err
}

func findGatewayByARN(ctx context.Context, conn *storagegateway.Client, arn string) (*storagegateway.DescribeGatewayInformationOutput, error) {
input := &storagegateway.DescribeGatewayInformationInput{
GatewayARN: aws.String(arn),
}

output, err := conn.DescribeGatewayInformation(ctx, input)

if operationErrorCode(err) == operationErrCodeGatewayNotFound || tfawserr.ErrCodeEquals(err, string(awstypes.ErrorCodeGatewayNotFound)) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output, nil
}

func findNFSFileShareByARN(ctx context.Context, conn *storagegateway.Client, arn string) (*awstypes.NFSFileShareInfo, error) {
input := &storagegateway.DescribeNFSFileSharesInput{
FileShareARNList: []string{arn},
454 changes: 273 additions & 181 deletions internal/service/storagegateway/gateway.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/service/storagegateway/gateway_test.go
Original file line number Diff line number Diff line change
@@ -897,11 +897,11 @@ func testAccCheckGatewayDestroy(ctx context.Context) resource.TestCheckFunc {
}
}

func testAccCheckGatewayExists(ctx context.Context, resourceName string, gateway *storagegateway.DescribeGatewayInformationOutput) resource.TestCheckFunc {
func testAccCheckGatewayExists(ctx context.Context, n string, v *storagegateway.DescribeGatewayInformationOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", resourceName)
return fmt.Errorf("Not found: %s", n)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).StorageGatewayClient(ctx)
@@ -912,7 +912,7 @@ func testAccCheckGatewayExists(ctx context.Context, resourceName string, gateway
return err
}

*gateway = *output
*v = *output

return nil
}
41 changes: 0 additions & 41 deletions internal/service/storagegateway/status.go
Original file line number Diff line number Diff line change
@@ -16,50 +16,9 @@ import (
)

const (
gatewayStatusConnected = "GatewayConnected"
storediSCSIVolumeStatusNotFound = "NotFound"
)

func statusGateway(ctx context.Context, conn *storagegateway.Client, gatewayARN string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeGatewayInformationInput{
GatewayARN: aws.String(gatewayARN),
}

output, err := conn.DescribeGatewayInformation(ctx, input)

if errs.IsAErrorMessageContains[*awstypes.InvalidGatewayRequestException](err, "The specified gateway is not connected") {
return output, string(awstypes.ErrorCodeGatewayNotConnected), nil
}

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

return output, gatewayStatusConnected, nil
}
}

func statusGatewayJoinDomain(ctx context.Context, conn *storagegateway.Client, gatewayARN string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &storagegateway.DescribeSMBSettingsInput{
GatewayARN: aws.String(gatewayARN),
}

output, err := conn.DescribeSMBSettings(ctx, input)

if errs.IsAErrorMessageContains[*awstypes.InvalidGatewayRequestException](err, "The specified gateway is not connected") {
return output, string(awstypes.ActiveDirectoryStatusUnknownError), nil
}

if err != nil {
return output, string(awstypes.ActiveDirectoryStatusUnknownError), err
}

return output, string(output.ActiveDirectoryStatus), nil
}
}

// statusStorediSCSIVolume fetches the Volume and its Status
func statusStorediSCSIVolume(ctx context.Context, conn *storagegateway.Client, volumeARN string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
53 changes: 5 additions & 48 deletions internal/service/storagegateway/wait.go
Original file line number Diff line number Diff line change
@@ -10,59 +10,16 @@ import (
"github.com/aws/aws-sdk-go-v2/service/storagegateway"
awstypes "github.com/aws/aws-sdk-go-v2/service/storagegateway/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
)

const (
gatewayConnectedMinTimeout = 10 * time.Second
gatewayConnectedContinuousTargetOccurence = 6
gatewayJoinDomainJoinedTimeout = 5 * time.Minute
storediSCSIVolumeAvailableTimeout = 5 * time.Minute
nfsFileShareAvailableDelay = 5 * time.Second
nfsFileShareDeletedDelay = 5 * time.Second
smbFileShareAvailableDelay = 5 * time.Second
smbFileShareDeletedDelay = 5 * time.Second
fileSystemAssociationAvailableDelay = 5 * time.Second
fileSystemAssociationDeletedDelay = 5 * time.Second
storediSCSIVolumeAvailableTimeout = 5 * time.Minute
nfsFileShareAvailableDelay = 5 * time.Second
nfsFileShareDeletedDelay = 5 * time.Second
smbFileShareAvailableDelay = 5 * time.Second
smbFileShareDeletedDelay = 5 * time.Second
)

func waitGatewayConnected(ctx context.Context, conn *storagegateway.Client, gatewayARN string, timeout time.Duration) (*storagegateway.DescribeGatewayInformationOutput, error) {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.ErrorCodeGatewayNotConnected),
Target: []string{gatewayStatusConnected},
Refresh: statusGateway(ctx, conn, gatewayARN),
Timeout: timeout,
MinTimeout: gatewayConnectedMinTimeout,
ContinuousTargetOccurence: gatewayConnectedContinuousTargetOccurence, // Gateway activations can take a few seconds and can trigger a reboot of the Gateway
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

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

func waitGatewayJoinDomainJoined(ctx context.Context, conn *storagegateway.Client, volumeARN string) (*storagegateway.DescribeSMBSettingsOutput, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.ActiveDirectoryStatusJoining),
Target: enum.Slice(awstypes.ActiveDirectoryStatusJoined),
Refresh: statusGatewayJoinDomain(ctx, conn, volumeARN),
Timeout: gatewayJoinDomainJoinedTimeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

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

return nil, err
}

// waitStorediSCSIVolumeAvailable waits for a StoredIscsiVolume to return Available
func waitStorediSCSIVolumeAvailable(ctx context.Context, conn *storagegateway.Client, volumeARN string) (*storagegateway.DescribeStorediSCSIVolumesOutput, error) {
stateConf := &retry.StateChangeConf{