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

Clean up uses of aws-sdk-go-base/v2/awsv1shim/v2/tfawserr #39147

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/errs/unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion internal/service/dax/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/mwaa/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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),
}
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/service/mwaa/exports_test.go
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion internal/service/mwaa/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions internal/service/mwaa/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
r := ResourceEnvironment()
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
}
12 changes: 6 additions & 6 deletions internal/tfresource/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
Loading