Skip to content

Commit

Permalink
r/neptune_cluster_snapshot: Migrate to AWS SDK v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattburgess committed Jul 29, 2024
1 parent ba6cb7f commit f84370f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
38 changes: 16 additions & 22 deletions internal/service/neptune/cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/neptune"
awstypes "github.com/aws/aws-sdk-go-v2/service/neptune/types"
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
Expand Down Expand Up @@ -173,7 +173,7 @@ func resourceClusterSnapshotDelete(ctx context.Context, d *schema.ResourceData,
DBClusterSnapshotIdentifier: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeDBClusterSnapshotNotFoundFault) {
if errs.IsA[*awstypes.DBClusterSnapshotNotFoundFault](err) {
return diags
}

Expand Down Expand Up @@ -211,35 +211,29 @@ func findClusterSnapshot(ctx context.Context, conn *neptune.Client, input *neptu
return nil, err
}

return tfresource.AssertSinglePtrResult(output)
return tfresource.AssertSingleValueResult(output)
}

func findClusterSnapshots(ctx context.Context, conn *neptune.Client, input *neptune.DescribeDBClusterSnapshotsInput) ([]*awstypes.DBClusterSnapshot, error) {
var output []*awstypes.DBClusterSnapshot
func findClusterSnapshots(ctx context.Context, conn *neptune.Client, input *neptune.DescribeDBClusterSnapshotsInput) ([]awstypes.DBClusterSnapshot, error) {
var output []awstypes.DBClusterSnapshot

err := conn.DescribeDBClusterSnapshotsPagesWithContext(ctx, input, func(page *neptune.DescribeDBClusterSnapshotsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
pages := neptune.NewDescribeDBClusterSnapshotsPaginator(conn, input)

for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

for _, v := range page.DBClusterSnapshots {
if v != nil {
output = append(output, v)
if errs.IsA[*awstypes.DBClusterSnapshotNotFoundFault](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeDBClusterSnapshotNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
if err != nil {
return nil, err
}
}

if err != nil {
return nil, err
output = append(output, page.DBClusterSnapshots...)
}

return output, nil
Expand Down
1 change: 0 additions & 1 deletion internal/service/neptune/cluster_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/service/neptune"
awstypes "github.com/aws/aws-sdk-go-v2/service/neptune/types"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down

0 comments on commit f84370f

Please sign in to comment.