From cee1643d55afb20f8b0c21fc0937c6f8f59687a9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Sep 2024 15:18:44 -0400 Subject: [PATCH 1/5] dax: 'aws-sdk-go-base/v2/awsv1shim/v2/tfawserr' -> 'aws-sdk-go-base/v2/tfawserr'. --- internal/service/dax/cluster_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/dax/cluster_test.go b/internal/service/dax/cluster_test.go index a134b6048b8..69d82dd5e18 100644 --- a/internal/service/dax/cluster_test.go +++ b/internal/service/dax/cluster_test.go @@ -12,7 +12,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/dax" awstypes "github.com/aws/aws-sdk-go-v2/service/dax/types" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -355,6 +355,7 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { input := &dax.DescribeClustersInput{} _, err := conn.DescribeClusters(ctx, input) + if acctest.PreCheckSkipError(err) || tfawserr.ErrMessageContains(err, "InvalidParameterValueException", "Access Denied to API Version: DAX_V3") { t.Skipf("skipping acceptance testing: %s", err) } From 3fea9aac0b57d06e57fb0e5086515b7a4a39a910 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Sep 2024 15:18:57 -0400 Subject: [PATCH 2/5] mwaa: 'aws-sdk-go-base/v2/awsv1shim/v2/tfawserr' -> 'aws-sdk-go-base/v2/tfawserr'. --- internal/service/mwaa/sweep.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/service/mwaa/sweep.go b/internal/service/mwaa/sweep.go index af134dd7ade..d17b365f546 100644 --- a/internal/service/mwaa/sweep.go +++ b/internal/service/mwaa/sweep.go @@ -8,8 +8,7 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/service/mwaa" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "github.com/hashicorp/go-multierror" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" @@ -28,34 +27,37 @@ func sweepEnvironment(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } + input := &mwaa.ListEnvironmentsInput{} conn := client.MWAAClient(ctx) - sweepResources := make([]sweep.Sweepable, 0) - var sweeperErrs *multierror.Error - pages := mwaa.NewListEnvironmentsPaginator(conn, &mwaa.ListEnvironmentsInput{}) + pages := mwaa.NewListEnvironmentsPaginator(conn, input) for pages.HasMorePages() { page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) || tfawserr.ErrCodeEquals(err, "InternalFailure") { + log.Printf("[WARN] Skipping MWAA Environment sweep for %s: %s", region, err) + return nil + } + if err != nil { - if awsv2.SkipSweepError(err) || tfawserr.ErrCodeEquals(err, "InternalFailure") { - log.Printf("[WARN] Skipping MWAA Environment sweep for %s: %s", region, err) - return nil - } - return fmt.Errorf("error retrieving MWAA Environment: %s", err) + return fmt.Errorf("error listing MWAA Environments (%s): %w", region, err) } - for _, name := range page.Environments { + for _, v := range page.Environments { r := ResourceEnvironment() d := r.Data(nil) - d.SetId(name) + d.SetId(v) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } } - if err := sweep.SweepOrchestrator(ctx, sweepResources); err != nil { - sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error sweeping MWAA Environment: %w", err)) + err = sweep.SweepOrchestrator(ctx, sweepResources) + + if err != nil { + return fmt.Errorf("error sweeping MWAA Environments (%s): %w", region, err) } - return sweeperErrs.ErrorOrNil() + return nil } From 8deb6e4d1a9ff5c39b4550acb797f84d3baf619d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Sep 2024 15:22:48 -0400 Subject: [PATCH 3/5] mwaa: Reduce visibility. --- internal/service/mwaa/environment.go | 8 ++++---- internal/service/mwaa/exports_test.go | 11 +++++++++++ internal/service/mwaa/sweep.go | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 internal/service/mwaa/exports_test.go diff --git a/internal/service/mwaa/environment.go b/internal/service/mwaa/environment.go index 1c368146283..7b28bc6a849 100644 --- a/internal/service/mwaa/environment.go +++ b/internal/service/mwaa/environment.go @@ -35,7 +35,7 @@ const ( // @SDKResource("aws_mwaa_environment", name="Environment") // @Tags(identifierAttribute="arn") -func ResourceEnvironment() *schema.Resource { +func resourceEnvironment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceEnvironmentCreate, ReadWithoutTimeout: resourceEnvironmentRead, @@ -441,7 +441,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i conn := meta.(*conns.AWSClient).MWAAClient(ctx) - environment, err := FindEnvironmentByName(ctx, conn, d.Id()) + environment, err := findEnvironmentByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] MWAA Environment %s not found, removing from state", d.Id()) @@ -661,7 +661,7 @@ func environmentModuleLoggingConfigurationSchema() *schema.Resource { } } -func FindEnvironmentByName(ctx context.Context, conn *mwaa.Client, name string) (*awstypes.Environment, error) { +func findEnvironmentByName(ctx context.Context, conn *mwaa.Client, name string) (*awstypes.Environment, error) { input := &mwaa.GetEnvironmentInput{ Name: aws.String(name), } @@ -688,7 +688,7 @@ func FindEnvironmentByName(ctx context.Context, conn *mwaa.Client, name string) func statusEnvironment(ctx context.Context, conn *mwaa.Client, name string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - environment, err := FindEnvironmentByName(ctx, conn, name) + environment, err := findEnvironmentByName(ctx, conn, name) if tfresource.NotFound(err) { return nil, "", nil diff --git a/internal/service/mwaa/exports_test.go b/internal/service/mwaa/exports_test.go new file mode 100644 index 00000000000..32c7c12c039 --- /dev/null +++ b/internal/service/mwaa/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mwaa + +// Exports for use in tests only. +var ( + ResourceEnvironment = resourceEnvironment + + FindEnvironmentByName = findEnvironmentByName +) diff --git a/internal/service/mwaa/sweep.go b/internal/service/mwaa/sweep.go index d17b365f546..0b9ba529af9 100644 --- a/internal/service/mwaa/sweep.go +++ b/internal/service/mwaa/sweep.go @@ -45,7 +45,7 @@ func sweepEnvironment(region string) error { } for _, v := range page.Environments { - r := ResourceEnvironment() + r := resourceEnvironment() d := r.Data(nil) d.SetId(v) From 6c6476d35d1703899c586a99a85982bc1132346d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Sep 2024 15:28:02 -0400 Subject: [PATCH 4/5] 'acctest.PreCheckSkipError' check both AWS SDK for Go v1 and v2 errors. --- internal/acctest/acctest.go | 19 ++++++++++--------- internal/errs/unsupported.go | 6 +++--- internal/tfresource/retry.go | 12 ++++++------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/internal/acctest/acctest.go b/internal/acctest/acctest.go index 69ad61eddc5..bbb789e7fcd 100644 --- a/internal/acctest/acctest.go +++ b/internal/acctest/acctest.go @@ -44,7 +44,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + tfawserr_sdkv1 "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + tfawserr_sdkv2 "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -1821,31 +1822,31 @@ func PreCheckSkipError(err error) bool { // GovCloud has endpoints that respond with (no message provided after the error code): // AccessDeniedException: // Ignore these API endpoints that exist but are not officially enabled - if tfawserr.ErrCodeEquals(err, "AccessDeniedException") { + if tfawserr_sdkv1.ErrCodeEquals(err, "AccessDeniedException") || tfawserr_sdkv2.ErrCodeEquals(err, "AccessDeniedException") { return true } // Ignore missing API endpoints - if tfawserr.ErrMessageContains(err, "RequestError", "send request failed") { + if tfawserr_sdkv1.ErrMessageContains(err, "RequestError", "send request failed") || tfawserr_sdkv2.ErrMessageContains(err, "RequestError", "send request failed") { return true } // Ignore unsupported API calls - if tfawserr.ErrCodeEquals(err, "UnknownOperationException") { + if tfawserr_sdkv1.ErrCodeEquals(err, "UnknownOperationException") || tfawserr_sdkv2.ErrCodeEquals(err, "UnknownOperationException") { return true } - if tfawserr.ErrCodeEquals(err, "UnsupportedOperation") { + if tfawserr_sdkv1.ErrCodeEquals(err, "UnsupportedOperation") || tfawserr_sdkv2.ErrCodeEquals(err, "UnsupportedOperation") { return true } - if tfawserr.ErrMessageContains(err, "InvalidInputException", "Unknown operation") { + if tfawserr_sdkv1.ErrMessageContains(err, "InvalidInputException", "Unknown operation") || tfawserr_sdkv2.ErrMessageContains(err, "InvalidInputException", "Unknown operation") { return true } - if tfawserr.ErrMessageContains(err, "InvalidAction", "is not valid") { + if tfawserr_sdkv1.ErrMessageContains(err, "InvalidAction", "is not valid") || tfawserr_sdkv2.ErrMessageContains(err, "InvalidAction", "is not valid") { return true } - if tfawserr.ErrMessageContains(err, "InvalidAction", "Unavailable Operation") { + if tfawserr_sdkv1.ErrMessageContains(err, "InvalidAction", "Unavailable Operation") || tfawserr_sdkv2.ErrMessageContains(err, "InvalidAction", "Unavailable Operation") { return true } // ignore when not authorized to call API from account - if tfawserr.ErrCodeEquals(err, "ForbiddenException") { + if tfawserr_sdkv1.ErrCodeEquals(err, "ForbiddenException") || tfawserr_sdkv2.ErrCodeEquals(err, "ForbiddenException") { return true } // Ignore missing API endpoints diff --git a/internal/errs/unsupported.go b/internal/errs/unsupported.go index 797e1596829..dfcd620c478 100644 --- a/internal/errs/unsupported.go +++ b/internal/errs/unsupported.go @@ -4,7 +4,7 @@ package errs import ( - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + tfawserr_sdkv1 "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" tfawserr_sdkv2 "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -106,9 +106,9 @@ func IsUnsupportedOperationInPartitionError(partition string, err error) bool { } func errCodeContains(err error, code string) bool { - return tfawserr.ErrCodeContains(err, code) || tfawserr_sdkv2.ErrCodeContains(err, code) + return tfawserr_sdkv1.ErrCodeContains(err, code) || tfawserr_sdkv2.ErrCodeContains(err, code) } func errMessageContains(err error, code, message string) bool { - return tfawserr.ErrMessageContains(err, code, message) || tfawserr_sdkv2.ErrMessageContains(err, code, message) + return tfawserr_sdkv1.ErrMessageContains(err, code, message) || tfawserr_sdkv2.ErrMessageContains(err, code, message) } diff --git a/internal/tfresource/retry.go b/internal/tfresource/retry.go index c12b38a6b28..56b840d27b2 100644 --- a/internal/tfresource/retry.go +++ b/internal/tfresource/retry.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + tfawserr_sdkv1 "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" tfawserr_sdkv2 "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/errs" @@ -96,7 +96,7 @@ func RetryGWhen[T any](ctx context.Context, timeout time.Duration, f func() (T, // RetryWhenAWSErrCodeEquals retries the specified function when it returns one of the specified AWS error codes. func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr.ErrCodeEquals(err, codes...) || tfawserr_sdkv2.ErrCodeEquals(err, codes...) { + if tfawserr_sdkv1.ErrCodeEquals(err, codes...) || tfawserr_sdkv2.ErrCodeEquals(err, codes...) { return true, err } @@ -107,7 +107,7 @@ func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f fun // RetryWhenAWSErrCodeContains retries the specified function when it returns an AWS error containing the specified code. func RetryWhenAWSErrCodeContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr.ErrCodeContains(err, code) || tfawserr_sdkv2.ErrCodeContains(err, code) { + if tfawserr_sdkv1.ErrCodeContains(err, code) || tfawserr_sdkv2.ErrCodeContains(err, code) { return true, err } @@ -118,7 +118,7 @@ func RetryWhenAWSErrCodeContains(ctx context.Context, timeout time.Duration, f f // RetryWhenAWSErrMessageContains retries the specified function when it returns an AWS error containing the specified message. func RetryWhenAWSErrMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code, message string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr.ErrMessageContains(err, code, message) || tfawserr_sdkv2.ErrMessageContains(err, code, message) { + if tfawserr_sdkv1.ErrMessageContains(err, code, message) || tfawserr_sdkv2.ErrMessageContains(err, code, message) { return true, err } @@ -130,7 +130,7 @@ func RetryWhenAWSErrMessageContains(ctx context.Context, timeout time.Duration, func RetryWhenMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes []string, messages []string) (interface{}, error) { return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { for i, message := range messages { - if tfawserr.ErrMessageContains(err, codes[i], message) || tfawserr_sdkv2.ErrMessageContains(err, codes[i], message) { + if tfawserr_sdkv1.ErrMessageContains(err, codes[i], message) || tfawserr_sdkv2.ErrMessageContains(err, codes[i], message) { return true, err } } @@ -143,7 +143,7 @@ func RetryWhenMessageContains(ctx context.Context, timeout time.Duration, f func func RetryGWhenMessageContains[T any](ctx context.Context, timeout time.Duration, f func() (T, error), codes []string, messages []string) (T, error) { return RetryGWhen(ctx, timeout, f, func(err error) (bool, error) { for i, message := range messages { - if tfawserr.ErrMessageContains(err, codes[i], message) || tfawserr_sdkv2.ErrMessageContains(err, codes[i], message) { + if tfawserr_sdkv1.ErrMessageContains(err, codes[i], message) || tfawserr_sdkv2.ErrMessageContains(err, codes[i], message) { return true, err } } From 30bccd240a6715892604c5a8492f7e1489f3cb16 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 4 Sep 2024 15:34:34 -0400 Subject: [PATCH 5/5] Run 'make gen'. --- internal/service/mwaa/service_package_gen.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/mwaa/service_package_gen.go b/internal/service/mwaa/service_package_gen.go index 544c283240a..9aad805d5fe 100644 --- a/internal/service/mwaa/service_package_gen.go +++ b/internal/service/mwaa/service_package_gen.go @@ -29,7 +29,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceEnvironment, + Factory: resourceEnvironment, TypeName: "aws_mwaa_environment", Name: "Environment", Tags: &types.ServicePackageResourceTags{