From b774bf31a1643e23a447f3eed52a8b465ef7e7b0 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:50:54 +0100 Subject: [PATCH 01/10] memorydb: Migrate to AWS SDK v2 --- go.mod | 1 + go.sum | 2 ++ internal/conns/awsclient_gen.go | 6 +++--- names/data/names_data.hcl | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index c7d6c7b1609..b2b6b7eb54c 100644 --- a/go.mod +++ b/go.mod @@ -152,6 +152,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/mediapackage v1.32.3 github.com/aws/aws-sdk-go-v2/service/mediapackagev2 v1.15.0 github.com/aws/aws-sdk-go-v2/service/mediastore v1.22.3 + github.com/aws/aws-sdk-go-v2/service/memorydb v1.21.3 github.com/aws/aws-sdk-go-v2/service/mq v1.25.3 github.com/aws/aws-sdk-go-v2/service/mwaa v1.29.4 github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.10.3 diff --git a/go.sum b/go.sum index 40c2d8b13f8..927e9e1d8fe 100644 --- a/go.sum +++ b/go.sum @@ -334,6 +334,8 @@ github.com/aws/aws-sdk-go-v2/service/mediapackagev2 v1.15.0 h1:1uii7pAgncfem27f3 github.com/aws/aws-sdk-go-v2/service/mediapackagev2 v1.15.0/go.mod h1:+R07/s3U8lJzEZDiwFxv/jmlSNbQjnoSqKaZEoqWt5Y= github.com/aws/aws-sdk-go-v2/service/mediastore v1.22.3 h1:WBVRvc0iIJdbdCkBjWRMVtUOMmAvOyN70x1KrBTOFm0= github.com/aws/aws-sdk-go-v2/service/mediastore v1.22.3/go.mod h1:plJWP1InGjEZiJvXfTlBqTBeMW8ddEZeIdYYFTYZMyE= +github.com/aws/aws-sdk-go-v2/service/memorydb v1.21.3 h1:yE9YBx0CNCrd+oZ1qEnsAhQOj7n3zjHo8J1TdDvAoiQ= +github.com/aws/aws-sdk-go-v2/service/memorydb v1.21.3/go.mod h1:y0n9wqlNiXxKkmb7FVBFrOd5jzpBnARZWMEXpAw3g3k= github.com/aws/aws-sdk-go-v2/service/mq v1.25.3 h1:SyRcb9GRPcoNKCuLnpj1qGIr/8stnVIf4DsuRhXIzEA= github.com/aws/aws-sdk-go-v2/service/mq v1.25.3/go.mod h1:Xu8nT/Yj64z5Gj1ebVB3drPEIBsPNDoFhx2xZDrdGlc= github.com/aws/aws-sdk-go-v2/service/mwaa v1.29.4 h1:lptYTP7Br5zll9USf2aKY1ZlN69vYAlZOSCv1Q+k1S4= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index d86f45d0d69..daf65cfb3b4 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -144,6 +144,7 @@ import ( mediapackage_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediapackage" mediapackagev2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediapackagev2" mediastore_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediastore" + memorydb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/memorydb" mq_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mq" mwaa_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mwaa" neptunegraph_sdkv2 "github.com/aws/aws-sdk-go-v2/service/neptunegraph" @@ -228,7 +229,6 @@ import ( licensemanager_sdkv1 "github.com/aws/aws-sdk-go/service/licensemanager" locationservice_sdkv1 "github.com/aws/aws-sdk-go/service/locationservice" macie2_sdkv1 "github.com/aws/aws-sdk-go/service/macie2" - memorydb_sdkv1 "github.com/aws/aws-sdk-go/service/memorydb" neptune_sdkv1 "github.com/aws/aws-sdk-go/service/neptune" networkmanager_sdkv1 "github.com/aws/aws-sdk-go/service/networkmanager" opensearchservice_sdkv1 "github.com/aws/aws-sdk-go/service/opensearchservice" @@ -877,8 +877,8 @@ func (c *AWSClient) MediaStoreClient(ctx context.Context) *mediastore_sdkv2.Clie return errs.Must(client[*mediastore_sdkv2.Client](ctx, c, names.MediaStore, make(map[string]any))) } -func (c *AWSClient) MemoryDBConn(ctx context.Context) *memorydb_sdkv1.MemoryDB { - return errs.Must(conn[*memorydb_sdkv1.MemoryDB](ctx, c, names.MemoryDB, make(map[string]any))) +func (c *AWSClient) MemoryDBClient(ctx context.Context) *memorydb_sdkv2.Client { + return errs.Must(client[*memorydb_sdkv2.Client](ctx, c, names.MemoryDB, make(map[string]any))) } func (c *AWSClient) NeptuneConn(ctx context.Context) *neptune_sdkv1.Neptune { diff --git a/names/data/names_data.hcl b/names/data/names_data.hcl index 1241359fb35..f10f95c1cdc 100644 --- a/names/data/names_data.hcl +++ b/names/data/names_data.hcl @@ -6083,7 +6083,7 @@ service "memorydb" { sdk { id = "MemoryDB" - client_version = [1] + client_version = [2] } names { From 49c6f6f8a8305906ef0df63a9c2dbccd14489f95 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:57:25 +0100 Subject: [PATCH 02/10] make gen --- internal/service/memorydb/generate.go | 4 +- internal/service/memorydb/list_pages_gen.go | 43 +++--- .../memorydb/service_endpoint_resolver_gen.go | 66 ++++---- .../memorydb/service_endpoints_gen_test.go | 146 +++++++++++++++--- .../service/memorydb/service_package_gen.go | 28 ++-- internal/service/memorydb/tags_gen.go | 36 ++--- 6 files changed, 207 insertions(+), 116 deletions(-) diff --git a/internal/service/memorydb/generate.go b/internal/service/memorydb/generate.go index 63b9e021dcd..70ada03740b 100644 --- a/internal/service/memorydb/generate.go +++ b/internal/service/memorydb/generate.go @@ -1,8 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeACLs,DescribeClusters,DescribeParameterGroups,DescribeSnapshots,DescribeSubnetGroups,DescribeUsers -//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ListTagsOutTagsElem=TagList -ServiceTagsSlice -UpdateTags +//go:generate go run ../../generate/listpages/main.go -AWSSDKVersion=2 -ListOps=DescribeACLs,DescribeClusters,DescribeParameterGroups,DescribeSnapshots,DescribeSubnetGroups,DescribeUsers +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTags -ListTagsOutTagsElem=TagList -ServiceTagsSlice -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/memorydb/list_pages_gen.go b/internal/service/memorydb/list_pages_gen.go index b38dfea16b8..f88d34a52a3 100644 --- a/internal/service/memorydb/list_pages_gen.go +++ b/internal/service/memorydb/list_pages_gen.go @@ -1,23 +1,22 @@ -// Code generated by "internal/generate/listpages/main.go -ListOps=DescribeACLs,DescribeClusters,DescribeParameterGroups,DescribeSnapshots,DescribeSubnetGroups,DescribeUsers"; DO NOT EDIT. +// Code generated by "internal/generate/listpages/main.go -AWSSDKVersion=2 -ListOps=DescribeACLs,DescribeClusters,DescribeParameterGroups,DescribeSnapshots,DescribeSubnetGroups,DescribeUsers"; DO NOT EDIT. package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/aws/aws-sdk-go/service/memorydb/memorydbiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" ) -func describeACLsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeACLsInput, fn func(*memorydb.DescribeACLsOutput, bool) bool) error { +func describeACLsPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeACLsInput, fn func(*memorydb.DescribeACLsOutput, bool) bool) error { for { - output, err := conn.DescribeACLsWithContext(ctx, input) + output, err := conn.DescribeACLs(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } @@ -26,14 +25,14 @@ func describeACLsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, inpu } return nil } -func describeClustersPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeClustersInput, fn func(*memorydb.DescribeClustersOutput, bool) bool) error { +func describeClustersPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeClustersInput, fn func(*memorydb.DescribeClustersOutput, bool) bool) error { for { - output, err := conn.DescribeClustersWithContext(ctx, input) + output, err := conn.DescribeClusters(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } @@ -42,14 +41,14 @@ func describeClustersPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, } return nil } -func describeParameterGroupsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeParameterGroupsInput, fn func(*memorydb.DescribeParameterGroupsOutput, bool) bool) error { +func describeParameterGroupsPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeParameterGroupsInput, fn func(*memorydb.DescribeParameterGroupsOutput, bool) bool) error { for { - output, err := conn.DescribeParameterGroupsWithContext(ctx, input) + output, err := conn.DescribeParameterGroups(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } @@ -58,14 +57,14 @@ func describeParameterGroupsPages(ctx context.Context, conn memorydbiface.Memory } return nil } -func describeSnapshotsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeSnapshotsInput, fn func(*memorydb.DescribeSnapshotsOutput, bool) bool) error { +func describeSnapshotsPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeSnapshotsInput, fn func(*memorydb.DescribeSnapshotsOutput, bool) bool) error { for { - output, err := conn.DescribeSnapshotsWithContext(ctx, input) + output, err := conn.DescribeSnapshots(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } @@ -74,14 +73,14 @@ func describeSnapshotsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, } return nil } -func describeSubnetGroupsPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeSubnetGroupsInput, fn func(*memorydb.DescribeSubnetGroupsOutput, bool) bool) error { +func describeSubnetGroupsPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeSubnetGroupsInput, fn func(*memorydb.DescribeSubnetGroupsOutput, bool) bool) error { for { - output, err := conn.DescribeSubnetGroupsWithContext(ctx, input) + output, err := conn.DescribeSubnetGroups(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } @@ -90,14 +89,14 @@ func describeSubnetGroupsPages(ctx context.Context, conn memorydbiface.MemoryDBA } return nil } -func describeUsersPages(ctx context.Context, conn memorydbiface.MemoryDBAPI, input *memorydb.DescribeUsersInput, fn func(*memorydb.DescribeUsersOutput, bool) bool) error { +func describeUsersPages(ctx context.Context, conn *memorydb.Client, input *memorydb.DescribeUsersInput, fn func(*memorydb.DescribeUsersOutput, bool) bool) error { for { - output, err := conn.DescribeUsersWithContext(ctx, input) + output, err := conn.DescribeUsers(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.NextToken) == "" + lastPage := aws.ToString(output.NextToken) == "" if !fn(output, lastPage) || lastPage { break } diff --git a/internal/service/memorydb/service_endpoint_resolver_gen.go b/internal/service/memorydb/service_endpoint_resolver_gen.go index 185906c0b20..70fe548a565 100644 --- a/internal/service/memorydb/service_endpoint_resolver_gen.go +++ b/internal/service/memorydb/service_endpoint_resolver_gen.go @@ -6,65 +6,63 @@ import ( "context" "fmt" "net" - "net/url" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + memorydb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/memorydb" + smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/errs" ) -var _ endpoints_sdkv1.Resolver = resolverSDKv1{} +var _ memorydb_sdkv2.EndpointResolverV2 = resolverSDKv2{} -type resolverSDKv1 struct { - ctx context.Context +type resolverSDKv2 struct { + defaultResolver memorydb_sdkv2.EndpointResolverV2 } -func newEndpointResolverSDKv1(ctx context.Context) resolverSDKv1 { - return resolverSDKv1{ - ctx: ctx, +func newEndpointResolverSDKv2() resolverSDKv2 { + return resolverSDKv2{ + defaultResolver: memorydb_sdkv2.NewDefaultEndpointResolverV2(), } } -func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoints_sdkv1.Options)) (endpoint endpoints_sdkv1.ResolvedEndpoint, err error) { - ctx := r.ctx +func (r resolverSDKv2) ResolveEndpoint(ctx context.Context, params memorydb_sdkv2.EndpointParameters) (endpoint smithyendpoints.Endpoint, err error) { + params = params.WithDefaults() + useFIPS := aws_sdkv2.ToBool(params.UseFIPS) - var opt endpoints_sdkv1.Options - opt.Set(opts...) - - useFIPS := opt.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled + if eps := params.Endpoint; aws_sdkv2.ToString(eps) != "" { + tflog.Debug(ctx, "setting endpoint", map[string]any{ + "tf_aws.endpoint": endpoint, + }) - defaultResolver := endpoints_sdkv1.DefaultResolver() + if useFIPS { + tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") + params.UseFIPS = aws_sdkv2.Bool(false) + } - if useFIPS { + return r.defaultResolver.ResolveEndpoint(ctx, params) + } else if useFIPS { ctx = tflog.SetField(ctx, "tf_aws.use_fips", useFIPS) - endpoint, err = defaultResolver.EndpointFor(service, region, opts...) + endpoint, err = r.defaultResolver.ResolveEndpoint(ctx, params) if err != nil { return endpoint, err } tflog.Debug(ctx, "endpoint resolved", map[string]any{ - "tf_aws.endpoint": endpoint.URL, + "tf_aws.endpoint": endpoint.URI.String(), }) - var endpointURL *url.URL - endpointURL, err = url.Parse(endpoint.URL) - if err != nil { - return endpoint, err - } - - hostname := endpointURL.Hostname() + hostname := endpoint.URI.Hostname() _, err = net.LookupHost(hostname) if err != nil { if dnsErr, ok := errs.As[*net.DNSError](err); ok && dnsErr.IsNotFound { tflog.Debug(ctx, "default endpoint host not found, disabling FIPS", map[string]any{ "tf_aws.hostname": hostname, }) - opts = append(opts, func(o *endpoints_sdkv1.Options) { - o.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled - }) + params.UseFIPS = aws_sdkv2.Bool(false) } else { - err = fmt.Errorf("looking up accessanalyzer endpoint %q: %s", hostname, err) + err = fmt.Errorf("looking up memorydb endpoint %q: %s", hostname, err) return } } else { @@ -72,5 +70,13 @@ func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoin } } - return defaultResolver.EndpointFor(service, region, opts...) + return r.defaultResolver.ResolveEndpoint(ctx, params) +} + +func withBaseEndpoint(endpoint string) func(*memorydb_sdkv2.Options) { + return func(o *memorydb_sdkv2.Options) { + if endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + } } diff --git a/internal/service/memorydb/service_endpoints_gen_test.go b/internal/service/memorydb/service_endpoints_gen_test.go index 1e19c62146f..f4fad8ba587 100644 --- a/internal/service/memorydb/service_endpoints_gen_test.go +++ b/internal/service/memorydb/service_endpoints_gen_test.go @@ -4,18 +4,22 @@ package memorydb_test import ( "context" + "errors" "fmt" "maps" "net" "net/url" "os" "path/filepath" + "reflect" "strings" "testing" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - memorydb_sdkv1 "github.com/aws/aws-sdk-go/service/memorydb" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + memorydb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/memorydb" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -240,54 +244,63 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := memorydb_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(memorydb_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), memorydb_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func defaultFIPSEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := memorydb_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(memorydb_sdkv1.EndpointsID, region, func(opt *endpoints.Options) { - opt.UseFIPSEndpoint = endpoints.FIPSEndpointStateEnabled + ep, err := r.ResolveEndpoint(context.Background(), memorydb_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + UseFIPS: aws_sdkv2.Bool(true), }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() - client := meta.MemoryDBConn(ctx) + client := meta.MemoryDBClient(ctx) - req, _ := client.DescribeClustersRequest(&memorydb_sdkv1.DescribeClustersInput{}) + var result apiCallParams - req.HTTPRequest.URL.Path = "/" - - return apiCallParams{ - endpoint: req.HTTPRequest.URL.String(), - region: aws_sdkv1.StringValue(client.Config.Region), + _, err := client.DescribeClusters(ctx, &memorydb_sdkv2.DescribeClustersInput{}, + func(opts *memorydb_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &result.endpoint), + addRetrieveRegionMiddleware(&result.region), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) } + + return result } func withNoConfig(_ *caseSetup) { @@ -466,6 +479,89 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } } +func addRetrieveEndpointURLMiddleware(t *testing.T, endpoint *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + retrieveEndpointURLMiddleware(t, endpoint), + middleware.After, + ) + } +} + +func retrieveEndpointURLMiddleware(t *testing.T, endpoint *string) middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Retrieve Endpoint", + func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + t.Helper() + + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + t.Fatalf("Expected *github.com/aws/smithy-go/transport/http.Request, got %s", fullTypeName(in.Request)) + } + + url := request.URL + url.RawQuery = "" + url.Path = "/" + + *endpoint = url.String() + + return next.HandleFinalize(ctx, in) + }) +} + +func addRetrieveRegionMiddleware(region *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Serialize.Add( + retrieveRegionMiddleware(region), + middleware.After, + ) + } +} + +func retrieveRegionMiddleware(region *string) middleware.SerializeMiddleware { + return middleware.SerializeMiddlewareFunc( + "Test: Retrieve Region", + func(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (middleware.SerializeOutput, middleware.Metadata, error) { + *region = awsmiddleware.GetRegion(ctx) + + return next.HandleSerialize(ctx, in) + }, + ) +} + +var errCancelOperation = fmt.Errorf("Test: Canceling request") + +func addCancelRequestMiddleware() func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + cancelRequestMiddleware(), + middleware.After, + ) + } +} + +// cancelRequestMiddleware creates a Smithy middleware that intercepts the request before sending and cancels it +func cancelRequestMiddleware() middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Cancel Requests", + func(_ context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + return middleware.FinalizeOutput{}, middleware.Metadata{}, errCancelOperation + }) +} + +func fullTypeName(i interface{}) string { + return fullValueTypeName(reflect.ValueOf(i)) +} + +func fullValueTypeName(v reflect.Value) string { + if v.Kind() == reflect.Ptr { + return "*" + fullValueTypeName(reflect.Indirect(v)) + } + + requestType := v.Type() + return fmt.Sprintf("%s.%s", requestType.PkgPath(), requestType.Name()) +} + func generateSharedConfigFile(config configFile) string { var buf strings.Builder diff --git a/internal/service/memorydb/service_package_gen.go b/internal/service/memorydb/service_package_gen.go index 9b026311bb6..4bcbfaf3613 100644 --- a/internal/service/memorydb/service_package_gen.go +++ b/internal/service/memorydb/service_package_gen.go @@ -5,10 +5,8 @@ package memorydb import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - memorydb_sdkv1 "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/terraform-plugin-log/tflog" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + memorydb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/memorydb" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -110,22 +108,14 @@ func (p *servicePackage) ServicePackageName() string { return names.MemoryDB } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*memorydb_sdkv1.MemoryDB, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*memorydb_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - cfg := aws_sdkv1.Config{} - - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { - tflog.Debug(ctx, "setting endpoint", map[string]any{ - "tf_aws.endpoint": endpoint, - }) - cfg.Endpoint = aws_sdkv1.String(endpoint) - } else { - cfg.EndpointResolver = newEndpointResolverSDKv1(ctx) - } - - return memorydb_sdkv1.New(sess.Copy(&cfg)), nil + return memorydb_sdkv2.NewFromConfig(cfg, + memorydb_sdkv2.WithEndpointResolverV2(newEndpointResolverSDKv2()), + withBaseEndpoint(config[names.AttrEndpoint].(string)), + ), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/memorydb/tags_gen.go b/internal/service/memorydb/tags_gen.go index 805f2ed38cc..bc87b071a28 100644 --- a/internal/service/memorydb/tags_gen.go +++ b/internal/service/memorydb/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/aws/aws-sdk-go/service/memorydb/memorydbiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +19,12 @@ import ( // listTags lists memorydb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *memorydb.Client, identifier string, optFns ...func(*memorydb.Options)) (tftags.KeyValueTags, error) { input := &memorydb.ListTagsInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsWithContext(ctx, input) + output, err := conn.ListTags(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +36,7 @@ func listTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier st // ListTags lists memorydb service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).MemoryDBConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).MemoryDBClient(ctx), identifier) if err != nil { return err @@ -52,11 +52,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // Tags returns memorydb service tags. -func Tags(tags tftags.KeyValueTags) []*memorydb.Tag { - result := make([]*memorydb.Tag, 0, len(tags)) +func Tags(tags tftags.KeyValueTags) []awstypes.Tag { + result := make([]awstypes.Tag, 0, len(tags)) for k, v := range tags.Map() { - tag := &memorydb.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -68,11 +68,11 @@ func Tags(tags tftags.KeyValueTags) []*memorydb.Tag { } // KeyValueTags creates tftags.KeyValueTags from memorydb service tags. -func KeyValueTags(ctx context.Context, tags []*memorydb.Tag) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { m := make(map[string]*string, len(tags)) for _, tag := range tags { - m[aws.StringValue(tag.Key)] = tag.Value + m[aws.ToString(tag.Key)] = tag.Value } return tftags.New(ctx, m) @@ -80,7 +80,7 @@ func KeyValueTags(ctx context.Context, tags []*memorydb.Tag) tftags.KeyValueTags // getTagsIn returns memorydb service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*memorydb.Tag { +func getTagsIn(ctx context.Context) []awstypes.Tag { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -91,7 +91,7 @@ func getTagsIn(ctx context.Context) []*memorydb.Tag { } // setTagsOut sets memorydb service tags in Context. -func setTagsOut(ctx context.Context, tags []*memorydb.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -100,7 +100,7 @@ func setTagsOut(ctx context.Context, tags []*memorydb.Tag) { // updateTags updates memorydb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *memorydb.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*memorydb.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -111,10 +111,10 @@ func updateTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier if len(removedTags) > 0 { input := &memorydb.UntagResourceInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -129,7 +129,7 @@ func updateTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -142,5 +142,5 @@ func updateTags(ctx context.Context, conn memorydbiface.MemoryDBAPI, identifier // UpdateTags updates memorydb service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).MemoryDBConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).MemoryDBClient(ctx), identifier, oldTags, newTags) } From a8178f8d208ffbf236f738f737e4047c345d5089 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:01:03 +0100 Subject: [PATCH 03/10] gopatch --- internal/service/memorydb/acl.go | 27 +++---- internal/service/memorydb/acl_data_source.go | 6 +- internal/service/memorydb/acl_test.go | 4 +- internal/service/memorydb/cluster.go | 59 +++++++-------- .../service/memorydb/cluster_data_source.go | 10 +-- internal/service/memorydb/cluster_test.go | 6 +- internal/service/memorydb/find.go | 43 +++++------ internal/service/memorydb/parameter_group.go | 73 ++++++++++--------- .../memorydb/parameter_group_data_source.go | 6 +- .../service/memorydb/parameter_group_test.go | 33 +++++---- internal/service/memorydb/snapshot.go | 49 +++++++------ .../service/memorydb/snapshot_data_source.go | 6 +- internal/service/memorydb/snapshot_test.go | 4 +- internal/service/memorydb/status.go | 29 ++++---- internal/service/memorydb/subnet_group.go | 25 ++++--- .../memorydb/subnet_group_data_source.go | 6 +- .../service/memorydb/subnet_group_test.go | 4 +- internal/service/memorydb/sweep.go | 31 ++++---- internal/service/memorydb/user.go | 34 +++++---- internal/service/memorydb/user_data_source.go | 10 +-- internal/service/memorydb/user_test.go | 4 +- internal/service/memorydb/wait.go | 23 +++--- 22 files changed, 252 insertions(+), 240 deletions(-) diff --git a/internal/service/memorydb/acl.go b/internal/service/memorydb/acl.go index b5b2ddc0229..17d91808418 100644 --- a/internal/service/memorydb/acl.go +++ b/internal/service/memorydb/acl.go @@ -7,9 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -81,7 +82,7 @@ func ResourceACL() *schema.Resource { func resourceACLCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &memorydb.CreateACLInput{ @@ -94,7 +95,7 @@ func resourceACLCreate(ctx context.Context, d *schema.ResourceData, meta interfa } log.Printf("[DEBUG] Creating MemoryDB ACL: %s", input) - _, err := conn.CreateACLWithContext(ctx, input) + _, err := conn.CreateACL(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB ACL (%s): %s", name, err) @@ -112,7 +113,7 @@ func resourceACLCreate(ctx context.Context, d *schema.ResourceData, meta interfa func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &memorydb.UpdateACLInput{ @@ -140,7 +141,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa initialUserNames := map[string]struct{}{} for _, userName := range initialState.UserNames { - initialUserNames[aws.StringValue(userName)] = struct{}{} + initialUserNames[aws.ToString(userName)] = struct{}{} } for _, v := range oldSet.Difference(newSet).List() { @@ -155,7 +156,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa if len(input.UserNamesToAdd) > 0 || len(input.UserNamesToRemove) > 0 { log.Printf("[DEBUG] Updating MemoryDB ACL (%s)", d.Id()) - _, err := conn.UpdateACLWithContext(ctx, input) + _, err := conn.UpdateACL(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MemoryDB ACL (%s): %s", d.Id(), err) } @@ -172,7 +173,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa func resourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) acl, err := FindACLByName(ctx, conn, d.Id()) @@ -189,7 +190,7 @@ func resourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface d.Set(names.AttrARN, acl.ARN) d.Set("minimum_engine_version", acl.MinimumEngineVersion) d.Set(names.AttrName, acl.Name) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(acl.Name))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(acl.Name))) d.Set("user_names", flex.FlattenStringSet(acl.UserNames)) return diags @@ -198,14 +199,14 @@ func resourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface func resourceACLDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) log.Printf("[DEBUG] Deleting MemoryDB ACL: (%s)", d.Id()) - _, err := conn.DeleteACLWithContext(ctx, &memorydb.DeleteACLInput{ + _, err := conn.DeleteACL(ctx, &memorydb.DeleteACLInput{ ACLName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeACLNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeACLNotFoundFault) { return diags } diff --git a/internal/service/memorydb/acl_data_source.go b/internal/service/memorydb/acl_data_source.go index 4127707e4e0..ad6dd7b732b 100644 --- a/internal/service/memorydb/acl_data_source.go +++ b/internal/service/memorydb/acl_data_source.go @@ -6,7 +6,7 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -48,7 +48,7 @@ func DataSourceACL() *schema.Resource { func dataSourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -59,7 +59,7 @@ func dataSourceACLRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB ACL", err)) } - d.SetId(aws.StringValue(acl.Name)) + d.SetId(aws.ToString(acl.Name)) d.Set(names.AttrARN, acl.ARN) d.Set("minimum_engine_version", acl.MinimumEngineVersion) diff --git a/internal/service/memorydb/acl_test.go b/internal/service/memorydb/acl_test.go index 81606fde74e..c6a6f99bd9d 100644 --- a/internal/service/memorydb/acl_test.go +++ b/internal/service/memorydb/acl_test.go @@ -297,7 +297,7 @@ func TestAccMemoryDBACL_update_userNames(t *testing.T) { func testAccCheckACLDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_acl" { @@ -332,7 +332,7 @@ func testAccCheckACLExists(ctx context.Context, n string) resource.TestCheckFunc return fmt.Errorf("No MemoryDB ACL ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindACLByName(ctx, conn, rs.Primary.Attributes[names.AttrName]) diff --git a/internal/service/memorydb/cluster.go b/internal/service/memorydb/cluster.go index 6da7b982844..ce2d4520a65 100644 --- a/internal/service/memorydb/cluster.go +++ b/internal/service/memorydb/cluster.go @@ -10,9 +10,10 @@ import ( "strconv" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -274,7 +275,7 @@ func endpointSchema() *schema.Schema { func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &memorydb.CreateClusterInput{ @@ -348,7 +349,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } log.Printf("[DEBUG] Creating MemoryDB Cluster: %s", input) - _, err := conn.CreateClusterWithContext(ctx, input) + _, err := conn.CreateCluster(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB Cluster (%s): %s", name, err) @@ -366,7 +367,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) if d.HasChangesExcept("final_snapshot_name", names.AttrTags, names.AttrTagsAll) { waitParameterGroupInSync := false @@ -397,13 +398,13 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChange("num_replicas_per_shard") { - input.ReplicaConfiguration = &memorydb.ReplicaConfigurationRequest{ + input.ReplicaConfiguration = &awstypes.ReplicaConfigurationRequest{ ReplicaCount: aws.Int64(int64(d.Get("num_replicas_per_shard").(int))), } } if d.HasChange("num_shards") { - input.ShardConfiguration = &memorydb.ShardConfigurationRequest{ + input.ShardConfiguration = &awstypes.ShardConfigurationRequest{ ShardCount: aws.Int64(int64(d.Get("num_shards").(int))), } } @@ -450,7 +451,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int log.Printf("[DEBUG] Updating MemoryDB Cluster (%s)", d.Id()) - _, err := conn.UpdateClusterWithContext(ctx, input) + _, err := conn.UpdateCluster(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MemoryDB Cluster (%s): %s", d.Id(), err) } @@ -478,7 +479,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) cluster, err := FindClusterByName(ctx, conn, d.Id()) @@ -501,7 +502,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrPort, v.Port) } - if v := aws.StringValue(cluster.DataTiering); v != "" { + if v := aws.ToString(cluster.DataTiering); v != "" { b, err := strconv.ParseBool(v) if err != nil { return sdkdiag.AppendErrorf(diags, "reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err) @@ -516,7 +517,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrKMSKeyARN, cluster.KmsKeyId) // KmsKeyId is actually an ARN here. d.Set("maintenance_window", cluster.MaintenanceWindow) d.Set(names.AttrName, cluster.Name) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(cluster.Name))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(cluster.Name))) d.Set("node_type", cluster.NodeType) numReplicasPerShard, err := deriveClusterNumReplicasPerShard(cluster) @@ -541,7 +542,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("snapshot_retention_limit", cluster.SnapshotRetentionLimit) d.Set("snapshot_window", cluster.SnapshotWindow) - if aws.StringValue(cluster.SnsTopicStatus) == ClusterSNSTopicStatusActive { + if aws.ToString(cluster.SnsTopicStatus) == ClusterSNSTopicStatusActive { d.Set(names.AttrSNSTopicARN, cluster.SnsTopicArn) } else { d.Set(names.AttrSNSTopicARN, "") @@ -556,7 +557,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) input := &memorydb.DeleteClusterInput{ ClusterName: aws.String(d.Id()), @@ -567,9 +568,9 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int } log.Printf("[DEBUG] Deleting MemoryDB Cluster: (%s)", d.Id()) - _, err := conn.DeleteClusterWithContext(ctx, input) + _, err := conn.DeleteCluster(ctx, input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeClusterNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeClusterNotFoundFault) { return diags } @@ -592,25 +593,25 @@ func nodeHash(v interface{}) int { return create.StringHashcode(v.(map[string]interface{})[names.AttrName].(string)) } -func flattenEndpoint(endpoint *memorydb.Endpoint) []interface{} { +func flattenEndpoint(endpoint *awstypes.Endpoint) []interface{} { if endpoint == nil { return []interface{}{} } m := map[string]interface{}{} - if v := aws.StringValue(endpoint.Address); v != "" { + if v := aws.ToString(endpoint.Address); v != "" { m[names.AttrAddress] = v } - if v := aws.Int64Value(endpoint.Port); v != 0 { + if v := aws.ToInt64(endpoint.Port); v != 0 { m[names.AttrPort] = v } return []interface{}{m} } -func flattenShards(shards []*memorydb.Shard) *schema.Set { +func flattenShards(shards []*awstypes.Shard) *schema.Set { shardSet := schema.NewSet(shardHash, nil) for _, shard := range shards { @@ -626,18 +627,18 @@ func flattenShards(shards []*memorydb.Shard) *schema.Set { } nodeSet.Add(map[string]interface{}{ - names.AttrAvailabilityZone: aws.StringValue(node.AvailabilityZone), - names.AttrCreateTime: aws.TimeValue(node.CreateTime).Format(time.RFC3339), + names.AttrAvailabilityZone: aws.ToString(node.AvailabilityZone), + names.AttrCreateTime: aws.ToTime(node.CreateTime).Format(time.RFC3339), names.AttrEndpoint: flattenEndpoint(node.Endpoint), - names.AttrName: aws.StringValue(node.Name), + names.AttrName: aws.ToString(node.Name), }) } shardSet.Add(map[string]interface{}{ - names.AttrName: aws.StringValue(shard.Name), - "num_nodes": int(aws.Int64Value(shard.NumberOfNodes)), + names.AttrName: aws.ToString(shard.Name), + "num_nodes": int(aws.ToInt64(shard.NumberOfNodes)), "nodes": nodeSet, - "slots": aws.StringValue(shard.Slots), + "slots": aws.ToString(shard.Slots), }) } @@ -649,15 +650,15 @@ func flattenShards(shards []*memorydb.Shard) *schema.Set { // assume that it's the same as that of the largest shard. // // For the sake of caution, this search is limited to stable shards. -func deriveClusterNumReplicasPerShard(cluster *memorydb.Cluster) (int, error) { +func deriveClusterNumReplicasPerShard(cluster *awstypes.Cluster) (int, error) { var maxNumberOfNodesPerShard int64 for _, shard := range cluster.Shards { - if aws.StringValue(shard.Status) != ClusterShardStatusAvailable { + if aws.ToString(shard.Status) != ClusterShardStatusAvailable { continue } - n := aws.Int64Value(shard.NumberOfNodes) + n := aws.ToInt64(shard.NumberOfNodes) if n > maxNumberOfNodesPerShard { maxNumberOfNodesPerShard = n } diff --git a/internal/service/memorydb/cluster_data_source.go b/internal/service/memorydb/cluster_data_source.go index 75365af1404..9d3f58dd4e0 100644 --- a/internal/service/memorydb/cluster_data_source.go +++ b/internal/service/memorydb/cluster_data_source.go @@ -7,7 +7,7 @@ import ( "context" "strconv" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -167,7 +167,7 @@ func DataSourceCluster() *schema.Resource { func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -178,7 +178,7 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB Cluster", err)) } - d.SetId(aws.StringValue(cluster.Name)) + d.SetId(aws.ToString(cluster.Name)) d.Set("acl_name", cluster.ACLName) d.Set(names.AttrARN, cluster.ARN) @@ -189,7 +189,7 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set(names.AttrPort, v.Port) } - if v := aws.StringValue(cluster.DataTiering); v != "" { + if v := aws.ToString(cluster.DataTiering); v != "" { b, err := strconv.ParseBool(v) if err != nil { return sdkdiag.AppendErrorf(diags, "reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err) @@ -228,7 +228,7 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("snapshot_retention_limit", cluster.SnapshotRetentionLimit) d.Set("snapshot_window", cluster.SnapshotWindow) - if aws.StringValue(cluster.SnsTopicStatus) == ClusterSNSTopicStatusActive { + if aws.ToString(cluster.SnsTopicStatus) == ClusterSNSTopicStatusActive { d.Set(names.AttrSNSTopicARN, cluster.SnsTopicArn) } else { d.Set(names.AttrSNSTopicARN, "") diff --git a/internal/service/memorydb/cluster_test.go b/internal/service/memorydb/cluster_test.go index 72cd0c3c694..584083c678e 100644 --- a/internal/service/memorydb/cluster_test.go +++ b/internal/service/memorydb/cluster_test.go @@ -1062,7 +1062,7 @@ func TestAccMemoryDBCluster_Update_tags(t *testing.T) { func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_cluster" { @@ -1097,7 +1097,7 @@ func testAccCheckClusterExists(ctx context.Context, n string) resource.TestCheck return fmt.Errorf("No MemoryDB Cluster ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindClusterByName(ctx, conn, rs.Primary.Attributes[names.AttrName]) @@ -1107,7 +1107,7 @@ func testAccCheckClusterExists(ctx context.Context, n string) resource.TestCheck func testAccCheckSnapshotExistsByName(ctx context.Context, snapshotName string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindSnapshotByName(ctx, conn, snapshotName) diff --git a/internal/service/memorydb/find.go b/internal/service/memorydb/find.go index 93124d29636..6d6c6e3f534 100644 --- a/internal/service/memorydb/find.go +++ b/internal/service/memorydb/find.go @@ -6,21 +6,22 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" + "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/tfresource" ) -func FindACLByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.ACL, error) { +func FindACLByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.ACL, error) { input := memorydb.DescribeACLsInput{ ACLName: aws.String(name), } - output, err := conn.DescribeACLsWithContext(ctx, &input) + output, err := conn.DescribeACLs(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeACLNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeACLNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -42,15 +43,15 @@ func FindACLByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (* return output.ACLs[0], nil } -func FindClusterByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.Cluster, error) { +func FindClusterByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.Cluster, error) { input := memorydb.DescribeClustersInput{ ClusterName: aws.String(name), ShowShardDetails: aws.Bool(true), } - output, err := conn.DescribeClustersWithContext(ctx, &input) + output, err := conn.DescribeClusters(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeClusterNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeClusterNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -72,14 +73,14 @@ func FindClusterByName(ctx context.Context, conn *memorydb.MemoryDB, name string return output.Clusters[0], nil } -func FindParameterGroupByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.ParameterGroup, error) { +func FindParameterGroupByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.ParameterGroup, error) { input := memorydb.DescribeParameterGroupsInput{ ParameterGroupName: aws.String(name), } - output, err := conn.DescribeParameterGroupsWithContext(ctx, &input) + output, err := conn.DescribeParameterGroups(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeParameterGroupNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeParameterGroupNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -101,14 +102,14 @@ func FindParameterGroupByName(ctx context.Context, conn *memorydb.MemoryDB, name return output.ParameterGroups[0], nil } -func FindSnapshotByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.Snapshot, error) { +func FindSnapshotByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.Snapshot, error) { input := memorydb.DescribeSnapshotsInput{ SnapshotName: aws.String(name), } - output, err := conn.DescribeSnapshotsWithContext(ctx, &input) + output, err := conn.DescribeSnapshots(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeSnapshotNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSnapshotNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -130,14 +131,14 @@ func FindSnapshotByName(ctx context.Context, conn *memorydb.MemoryDB, name strin return output.Snapshots[0], nil } -func FindSubnetGroupByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.SubnetGroup, error) { +func FindSubnetGroupByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.SubnetGroup, error) { input := memorydb.DescribeSubnetGroupsInput{ SubnetGroupName: aws.String(name), } - output, err := conn.DescribeSubnetGroupsWithContext(ctx, &input) + output, err := conn.DescribeSubnetGroups(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeSubnetGroupNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSubnetGroupNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -159,14 +160,14 @@ func FindSubnetGroupByName(ctx context.Context, conn *memorydb.MemoryDB, name st return output.SubnetGroups[0], nil } -func FindUserByName(ctx context.Context, conn *memorydb.MemoryDB, name string) (*memorydb.User, error) { +func FindUserByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.User, error) { input := memorydb.DescribeUsersInput{ UserName: aws.String(name), } - output, err := conn.DescribeUsersWithContext(ctx, &input) + output, err := conn.DescribeUsers(ctx, &input) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeUserNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeUserNotFoundFault) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/memorydb/parameter_group.go b/internal/service/memorydb/parameter_group.go index ca5f2daae97..883c435d84e 100644 --- a/internal/service/memorydb/parameter_group.go +++ b/internal/service/memorydb/parameter_group.go @@ -11,9 +11,10 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -100,7 +101,7 @@ func ResourceParameterGroup() *schema.Resource { func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &memorydb.CreateParameterGroupInput{ @@ -111,7 +112,7 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m } log.Printf("[DEBUG] Creating MemoryDB Parameter Group: %s", input) - output, err := conn.CreateParameterGroupWithContext(ctx, input) + output, err := conn.CreateParameterGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB Parameter Group (%s): %s", name, err) @@ -129,7 +130,7 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) if d.HasChange(names.AttrParameter) { o, n := d.GetChange(names.AttrParameter) @@ -146,7 +147,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m // Removing a parameter from state is equivalent to resetting it // to its default state. - var paramsToReset []*memorydb.ParameterNameValue + var paramsToReset []*awstypes.ParameterNameValue if len(toRemove) <= maxParams { paramsToReset, toRemove = toRemove[:], nil } else { @@ -161,7 +162,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m } for len(toAdd) > 0 { - var paramsToModify []*memorydb.ParameterNameValue + var paramsToModify []*awstypes.ParameterNameValue if len(toAdd) <= maxParams { paramsToModify, toAdd = toAdd[:], nil } else { @@ -182,7 +183,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) group, err := FindParameterGroupByName(ctx, conn, d.Id()) @@ -200,7 +201,7 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met d.Set(names.AttrDescription, group.Description) d.Set(names.AttrFamily, group.Family) d.Set(names.AttrName, group.Name) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(group.Name))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(group.Name))) userDefinedParameters := createUserDefinedParameterMap(d) @@ -219,14 +220,14 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) log.Printf("[DEBUG] Deleting MemoryDB Parameter Group: (%s)", d.Id()) - _, err := conn.DeleteParameterGroupWithContext(ctx, &memorydb.DeleteParameterGroupInput{ + _, err := conn.DeleteParameterGroup(ctx, &memorydb.DeleteParameterGroupInput{ ParameterGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeParameterGroupNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeParameterGroupNotFoundFault) { return diags } @@ -238,7 +239,7 @@ func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, m } // resetParameterGroupParameters resets the given parameters to their default values. -func resetParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, name string, parameters []*memorydb.ParameterNameValue) error { +func resetParameterGroupParameters(ctx context.Context, conn *memorydb.Client, name string, parameters []*awstypes.ParameterNameValue) error { var parameterNames []*string for _, parameter := range parameters { parameterNames = append(parameterNames, parameter.ParameterName) @@ -250,9 +251,9 @@ func resetParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, } return retry.RetryContext(ctx, 30*time.Second, func() *retry.RetryError { - _, err := conn.ResetParameterGroupWithContext(ctx, &input) + _, err := conn.ResetParameterGroup(ctx, &input) if err != nil { - if tfawserr.ErrMessageContains(err, memorydb.ErrCodeInvalidParameterGroupStateFault, " has pending changes") { + if tfawserr.ErrMessageContains(err, awstypes.ErrCodeInvalidParameterGroupStateFault, " has pending changes") { return retry.RetryableError(err) } return retry.NonRetryableError(err) @@ -262,12 +263,12 @@ func resetParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, } // modifyParameterGroupParameters updates the given parameters. -func modifyParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, name string, parameters []*memorydb.ParameterNameValue) error { +func modifyParameterGroupParameters(ctx context.Context, conn *memorydb.Client, name string, parameters []*awstypes.ParameterNameValue) error { input := memorydb.UpdateParameterGroupInput{ ParameterGroupName: aws.String(name), ParameterNameValues: parameters, } - _, err := conn.UpdateParameterGroupWithContext(ctx, &input) + _, err := conn.UpdateParameterGroup(ctx, &input) return err } @@ -276,13 +277,13 @@ func modifyParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB // // Parameters given in userDefined will be returned even if the value is equal // to the default. -func listParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, family, name string, userDefined map[string]string) ([]*memorydb.Parameter, error) { - query := func(ctx context.Context, parameterGroupName string) ([]*memorydb.Parameter, error) { +func listParameterGroupParameters(ctx context.Context, conn *memorydb.Client, family, name string, userDefined map[string]string) ([]*awstypes.Parameter, error) { + query := func(ctx context.Context, parameterGroupName string) ([]*awstypes.Parameter, error) { input := memorydb.DescribeParametersInput{ ParameterGroupName: aws.String(parameterGroupName), } - output, err := conn.DescribeParametersWithContext(ctx, &input) + output, err := conn.DescribeParameters(ctx, &input) if err != nil { return nil, err } @@ -302,7 +303,7 @@ func listParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, defaultValueByName := map[string]string{} for _, defaultPV := range defaults { - defaultValueByName[aws.StringValue(defaultPV.Name)] = aws.StringValue(defaultPV.Value) + defaultValueByName[aws.ToString(defaultPV.Name)] = aws.ToString(defaultPV.Value) } current, err := query(ctx, name) @@ -310,11 +311,11 @@ func listParameterGroupParameters(ctx context.Context, conn *memorydb.MemoryDB, return nil, err } - var result []*memorydb.Parameter + var result []*awstypes.Parameter for _, parameter := range current { - name := aws.StringValue(parameter.Name) - currentValue := aws.StringValue(parameter.Value) + name := aws.ToString(parameter.Name) + currentValue := aws.ToString(parameter.Value) defaultValue := defaultValueByName[name] _, isUserDefined := userDefined[name] @@ -337,7 +338,7 @@ func ParameterHash(v interface{}) int { } // ParameterChanges was copy-pasted from ElastiCache. -func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*memorydb.ParameterNameValue) { +func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*awstypes.ParameterNameValue) { if o == nil { o = new(schema.Set) } @@ -348,19 +349,19 @@ func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*memorydb.Paramet os := o.(*schema.Set) ns := n.(*schema.Set) - om := make(map[string]*memorydb.ParameterNameValue, os.Len()) + om := make(map[string]*awstypes.ParameterNameValue, os.Len()) for _, raw := range os.List() { param := raw.(map[string]interface{}) om[param[names.AttrName].(string)] = expandParameterNameValue(param) } - nm := make(map[string]*memorydb.ParameterNameValue, len(addOrUpdate)) + nm := make(map[string]*awstypes.ParameterNameValue, len(addOrUpdate)) for _, raw := range ns.List() { param := raw.(map[string]interface{}) nm[param[names.AttrName].(string)] = expandParameterNameValue(param) } // Remove: key is in old, but not in new - remove = make([]*memorydb.ParameterNameValue, 0, os.Len()) + remove = make([]*awstypes.ParameterNameValue, 0, os.Len()) for k := range om { if _, ok := nm[k]; !ok { remove = append(remove, om[k]) @@ -368,10 +369,10 @@ func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*memorydb.Paramet } // Add or Update: key is in new, but not in old or has changed value - addOrUpdate = make([]*memorydb.ParameterNameValue, 0, ns.Len()) + addOrUpdate = make([]*awstypes.ParameterNameValue, 0, ns.Len()) for k, nv := range nm { ov, ok := om[k] - if !ok || ok && (aws.StringValue(nv.ParameterValue) != aws.StringValue(ov.ParameterValue)) { + if !ok || ok && (aws.ToString(nv.ParameterValue) != aws.ToString(ov.ParameterValue)) { addOrUpdate = append(addOrUpdate, nm[k]) } } @@ -379,21 +380,21 @@ func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*memorydb.Paramet return remove, addOrUpdate } -func flattenParameters(list []*memorydb.Parameter) []map[string]interface{} { +func flattenParameters(list []*awstypes.Parameter) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { if i.Value != nil { result = append(result, map[string]interface{}{ - names.AttrName: strings.ToLower(aws.StringValue(i.Name)), - names.AttrValue: aws.StringValue(i.Value), + names.AttrName: strings.ToLower(aws.ToString(i.Name)), + names.AttrValue: aws.ToString(i.Value), }) } } return result } -func expandParameterNameValue(param map[string]interface{}) *memorydb.ParameterNameValue { - return &memorydb.ParameterNameValue{ +func expandParameterNameValue(param map[string]interface{}) *awstypes.ParameterNameValue { + return &awstypes.ParameterNameValue{ ParameterName: aws.String(param[names.AttrName].(string)), ParameterValue: aws.String(param[names.AttrValue].(string)), } diff --git a/internal/service/memorydb/parameter_group_data_source.go b/internal/service/memorydb/parameter_group_data_source.go index 63089db0f92..bfedb341827 100644 --- a/internal/service/memorydb/parameter_group_data_source.go +++ b/internal/service/memorydb/parameter_group_data_source.go @@ -6,7 +6,7 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -63,7 +63,7 @@ func DataSourceParameterGroup() *schema.Resource { func dataSourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -74,7 +74,7 @@ func dataSourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB Parameter Group", err)) } - d.SetId(aws.StringValue(group.Name)) + d.SetId(aws.ToString(group.Name)) d.Set(names.AttrARN, group.ARN) d.Set(names.AttrDescription, group.Description) diff --git a/internal/service/memorydb/parameter_group_test.go b/internal/service/memorydb/parameter_group_test.go index e7aaaaa6fe2..2a3409c18a0 100644 --- a/internal/service/memorydb/parameter_group_test.go +++ b/internal/service/memorydb/parameter_group_test.go @@ -9,8 +9,9 @@ import ( "reflect" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -272,7 +273,7 @@ func TestAccMemoryDBParameterGroup_update_tags(t *testing.T) { func testAccCheckParameterGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_parameter_group" { @@ -307,7 +308,7 @@ func testAccCheckParameterGroupExists(ctx context.Context, n string) resource.Te return fmt.Errorf("No MemoryDB Parameter Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindParameterGroupByName(ctx, conn, rs.Primary.Attributes[names.AttrName]) @@ -424,15 +425,15 @@ func TestParameterChanges(t *testing.T) { Name string Old *schema.Set New *schema.Set - ExpectedRemove []*memorydb.ParameterNameValue - ExpectedAddOrUpdate []*memorydb.ParameterNameValue + ExpectedRemove []*awstypes.ParameterNameValue + ExpectedAddOrUpdate []*awstypes.ParameterNameValue }{ { Name: "Empty", Old: new(schema.Set), New: new(schema.Set), - ExpectedRemove: []*memorydb.ParameterNameValue{}, - ExpectedAddOrUpdate: []*memorydb.ParameterNameValue{}, + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Remove all", @@ -443,13 +444,13 @@ func TestParameterChanges(t *testing.T) { }, }), New: new(schema.Set), - ExpectedRemove: []*memorydb.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("reserved-memory"), ParameterValue: aws.String(acctest.Ct0), }, }, - ExpectedAddOrUpdate: []*memorydb.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "No change", @@ -465,8 +466,8 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: acctest.Ct0, }, }), - ExpectedRemove: []*memorydb.ParameterNameValue{}, - ExpectedAddOrUpdate: []*memorydb.ParameterNameValue{}, + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Remove partial", @@ -486,13 +487,13 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: "yes", }, }), - ExpectedRemove: []*memorydb.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("reserved-memory"), ParameterValue: aws.String(acctest.Ct0), }, }, - ExpectedAddOrUpdate: []*memorydb.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Add to existing", @@ -512,8 +513,8 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: "always", }, }), - ExpectedRemove: []*memorydb.ParameterNameValue{}, - ExpectedAddOrUpdate: []*memorydb.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("appendfsync"), ParameterValue: aws.String("always"), diff --git a/internal/service/memorydb/snapshot.go b/internal/service/memorydb/snapshot.go index dcf582f82ec..7443f021fea 100644 --- a/internal/service/memorydb/snapshot.go +++ b/internal/service/memorydb/snapshot.go @@ -7,9 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -151,7 +152,7 @@ func ResourceSnapshot() *schema.Resource { func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &memorydb.CreateSnapshotInput{ @@ -165,7 +166,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, meta in } log.Printf("[DEBUG] Creating MemoryDB Snapshot: %s", input) - _, err := conn.CreateSnapshotWithContext(ctx, input) + _, err := conn.CreateSnapshot(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB Snapshot (%s): %s", name, err) @@ -188,7 +189,7 @@ func resourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, meta in func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) snapshot, err := FindSnapshotByName(ctx, conn, d.Id()) @@ -209,7 +210,7 @@ func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set(names.AttrClusterName, snapshot.ClusterConfiguration.Name) d.Set(names.AttrKMSKeyARN, snapshot.KmsKeyId) d.Set(names.AttrName, snapshot.Name) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(snapshot.Name))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(snapshot.Name))) d.Set(names.AttrSource, snapshot.Source) return diags @@ -218,14 +219,14 @@ func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, meta inte func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) log.Printf("[DEBUG] Deleting MemoryDB Snapshot: (%s)", d.Id()) - _, err := conn.DeleteSnapshotWithContext(ctx, &memorydb.DeleteSnapshotInput{ + _, err := conn.DeleteSnapshot(ctx, &memorydb.DeleteSnapshotInput{ SnapshotName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeSnapshotNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSnapshotNotFoundFault) { return diags } @@ -240,25 +241,25 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, meta in return diags } -func flattenClusterConfiguration(v *memorydb.ClusterConfiguration) []interface{} { +func flattenClusterConfiguration(v *awstypes.ClusterConfiguration) []interface{} { if v == nil { return []interface{}{} } m := map[string]interface{}{ - names.AttrDescription: aws.StringValue(v.Description), - names.AttrEngineVersion: aws.StringValue(v.EngineVersion), - "maintenance_window": aws.StringValue(v.MaintenanceWindow), - names.AttrName: aws.StringValue(v.Name), - "node_type": aws.StringValue(v.NodeType), - "num_shards": aws.Int64Value(v.NumShards), - names.AttrParameterGroupName: aws.StringValue(v.ParameterGroupName), - names.AttrPort: aws.Int64Value(v.Port), - "snapshot_retention_limit": aws.Int64Value(v.SnapshotRetentionLimit), - "snapshot_window": aws.StringValue(v.SnapshotWindow), - "subnet_group_name": aws.StringValue(v.SubnetGroupName), - names.AttrTopicARN: aws.StringValue(v.TopicArn), - names.AttrVPCID: aws.StringValue(v.VpcId), + names.AttrDescription: aws.ToString(v.Description), + names.AttrEngineVersion: aws.ToString(v.EngineVersion), + "maintenance_window": aws.ToString(v.MaintenanceWindow), + names.AttrName: aws.ToString(v.Name), + "node_type": aws.ToString(v.NodeType), + "num_shards": aws.ToInt64(v.NumShards), + names.AttrParameterGroupName: aws.ToString(v.ParameterGroupName), + names.AttrPort: aws.ToInt64(v.Port), + "snapshot_retention_limit": aws.ToInt64(v.SnapshotRetentionLimit), + "snapshot_window": aws.ToString(v.SnapshotWindow), + "subnet_group_name": aws.ToString(v.SubnetGroupName), + names.AttrTopicARN: aws.ToString(v.TopicArn), + names.AttrVPCID: aws.ToString(v.VpcId), } return []interface{}{m} diff --git a/internal/service/memorydb/snapshot_data_source.go b/internal/service/memorydb/snapshot_data_source.go index 734a27c9ebd..8790a056258 100644 --- a/internal/service/memorydb/snapshot_data_source.go +++ b/internal/service/memorydb/snapshot_data_source.go @@ -6,7 +6,7 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -110,7 +110,7 @@ func DataSourceSnapshot() *schema.Resource { func dataSourceSnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -121,7 +121,7 @@ func dataSourceSnapshotRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB Snapshot", err)) } - d.SetId(aws.StringValue(snapshot.Name)) + d.SetId(aws.ToString(snapshot.Name)) d.Set(names.AttrARN, snapshot.ARN) if err := d.Set("cluster_configuration", flattenClusterConfiguration(snapshot.ClusterConfiguration)); err != nil { diff --git a/internal/service/memorydb/snapshot_test.go b/internal/service/memorydb/snapshot_test.go index 35eb592f457..3a125a5a3ff 100644 --- a/internal/service/memorydb/snapshot_test.go +++ b/internal/service/memorydb/snapshot_test.go @@ -234,7 +234,7 @@ func TestAccMemoryDBSnapshot_update_tags(t *testing.T) { func testAccCheckSnapshotDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_snapshot" { @@ -269,7 +269,7 @@ func testAccCheckSnapshotExists(ctx context.Context, n string) resource.TestChec return fmt.Errorf("No MemoryDB Snapshot ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindSnapshotByName(ctx, conn, rs.Primary.Attributes[names.AttrName]) diff --git a/internal/service/memorydb/status.go b/internal/service/memorydb/status.go index 54af4c86037..b72718f38d0 100644 --- a/internal/service/memorydb/status.go +++ b/internal/service/memorydb/status.go @@ -6,14 +6,15 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // statusACL fetches the MemoryDB ACL and its status. -func statusACL(ctx context.Context, conn *memorydb.MemoryDB, aclName string) retry.StateRefreshFunc { +func statusACL(ctx context.Context, conn *memorydb.Client, aclName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { acl, err := FindACLByName(ctx, conn, aclName) @@ -25,12 +26,12 @@ func statusACL(ctx context.Context, conn *memorydb.MemoryDB, aclName string) ret return nil, "", err } - return acl, aws.StringValue(acl.Status), nil + return acl, aws.ToString(acl.Status), nil } } // statusCluster fetches the MemoryDB Cluster and its status. -func statusCluster(ctx context.Context, conn *memorydb.MemoryDB, clusterName string) retry.StateRefreshFunc { +func statusCluster(ctx context.Context, conn *memorydb.Client, clusterName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { cluster, err := FindClusterByName(ctx, conn, clusterName) @@ -42,12 +43,12 @@ func statusCluster(ctx context.Context, conn *memorydb.MemoryDB, clusterName str return nil, "", err } - return cluster, aws.StringValue(cluster.Status), nil + return cluster, aws.ToString(cluster.Status), nil } } // statusClusterParameterGroup fetches the MemoryDB Cluster and its parameter group status. -func statusClusterParameterGroup(ctx context.Context, conn *memorydb.MemoryDB, clusterName string) retry.StateRefreshFunc { +func statusClusterParameterGroup(ctx context.Context, conn *memorydb.Client, clusterName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { cluster, err := FindClusterByName(ctx, conn, clusterName) @@ -59,12 +60,12 @@ func statusClusterParameterGroup(ctx context.Context, conn *memorydb.MemoryDB, c return nil, "", err } - return cluster, aws.StringValue(cluster.ParameterGroupStatus), nil + return cluster, aws.ToString(cluster.ParameterGroupStatus), nil } } // statusClusterSecurityGroups fetches the MemoryDB Cluster and its security group status. -func statusClusterSecurityGroups(ctx context.Context, conn *memorydb.MemoryDB, clusterName string) retry.StateRefreshFunc { +func statusClusterSecurityGroups(ctx context.Context, conn *memorydb.Client, clusterName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { cluster, err := FindClusterByName(ctx, conn, clusterName) @@ -80,7 +81,7 @@ func statusClusterSecurityGroups(ctx context.Context, conn *memorydb.MemoryDB, c // When at least one security group change is being applied (whether // that be adding or removing an SG), say that we're still in progress. - if aws.StringValue(sg.Status) != ClusterSecurityGroupStatusActive { + if aws.ToString(sg.Status) != ClusterSecurityGroupStatusActive { return cluster, ClusterSecurityGroupStatusModifying, nil } } @@ -90,7 +91,7 @@ func statusClusterSecurityGroups(ctx context.Context, conn *memorydb.MemoryDB, c } // statusSnapshot fetches the MemoryDB Snapshot and its status. -func statusSnapshot(ctx context.Context, conn *memorydb.MemoryDB, snapshotName string) retry.StateRefreshFunc { +func statusSnapshot(ctx context.Context, conn *memorydb.Client, snapshotName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { snapshot, err := FindSnapshotByName(ctx, conn, snapshotName) @@ -102,12 +103,12 @@ func statusSnapshot(ctx context.Context, conn *memorydb.MemoryDB, snapshotName s return nil, "", err } - return snapshot, aws.StringValue(snapshot.Status), nil + return snapshot, aws.ToString(snapshot.Status), nil } } // statusUser fetches the MemoryDB user and its status. -func statusUser(ctx context.Context, conn *memorydb.MemoryDB, userName string) retry.StateRefreshFunc { +func statusUser(ctx context.Context, conn *memorydb.Client, userName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { user, err := FindUserByName(ctx, conn, userName) @@ -119,6 +120,6 @@ func statusUser(ctx context.Context, conn *memorydb.MemoryDB, userName string) r return nil, "", err } - return user, aws.StringValue(user.Status), nil + return user, aws.ToString(user.Status), nil } } diff --git a/internal/service/memorydb/subnet_group.go b/internal/service/memorydb/subnet_group.go index 314802c87e4..891bd7c5647 100644 --- a/internal/service/memorydb/subnet_group.go +++ b/internal/service/memorydb/subnet_group.go @@ -7,9 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -83,7 +84,7 @@ func ResourceSubnetGroup() *schema.Resource { func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &memorydb.CreateSubnetGroupInput{ @@ -94,7 +95,7 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta } log.Printf("[DEBUG] Creating MemoryDB Subnet Group: %s", input) - _, err := conn.CreateSubnetGroupWithContext(ctx, input) + _, err := conn.CreateSubnetGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB Subnet Group (%s): %s", name, err) @@ -108,7 +109,7 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &memorydb.UpdateSubnetGroupInput{ @@ -118,7 +119,7 @@ func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta } log.Printf("[DEBUG] Updating MemoryDB Subnet Group: %s", input) - _, err := conn.UpdateSubnetGroupWithContext(ctx, input) + _, err := conn.UpdateSubnetGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MemoryDB Subnet Group (%s): %s", d.Id(), err) @@ -131,7 +132,7 @@ func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) group, err := FindSubnetGroupByName(ctx, conn, d.Id()) @@ -154,7 +155,7 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrDescription, group.Description) d.Set(names.AttrSubnetIDs, flex.FlattenStringSet(subnetIds)) d.Set(names.AttrName, group.Name) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(group.Name))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(group.Name))) d.Set(names.AttrVPCID, group.VpcId) return diags @@ -163,14 +164,14 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i func resourceSubnetGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) log.Printf("[DEBUG] Deleting MemoryDB Subnet Group: (%s)", d.Id()) - _, err := conn.DeleteSubnetGroupWithContext(ctx, &memorydb.DeleteSubnetGroupInput{ + _, err := conn.DeleteSubnetGroup(ctx, &memorydb.DeleteSubnetGroupInput{ SubnetGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeSubnetGroupNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSubnetGroupNotFoundFault) { return diags } diff --git a/internal/service/memorydb/subnet_group_data_source.go b/internal/service/memorydb/subnet_group_data_source.go index c7830eb13a3..84e5db73d9a 100644 --- a/internal/service/memorydb/subnet_group_data_source.go +++ b/internal/service/memorydb/subnet_group_data_source.go @@ -6,7 +6,7 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -52,7 +52,7 @@ func DataSourceSubnetGroup() *schema.Resource { func dataSourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -63,7 +63,7 @@ func dataSourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB Subnet Group", err)) } - d.SetId(aws.StringValue(group.Name)) + d.SetId(aws.ToString(group.Name)) var subnetIds []*string for _, subnet := range group.Subnets { diff --git a/internal/service/memorydb/subnet_group_test.go b/internal/service/memorydb/subnet_group_test.go index 690d6ed89ec..9c7cf1d1a26 100644 --- a/internal/service/memorydb/subnet_group_test.go +++ b/internal/service/memorydb/subnet_group_test.go @@ -298,7 +298,7 @@ func TestAccMemoryDBSubnetGroup_update_tags(t *testing.T) { func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_subnet_group" { @@ -333,7 +333,7 @@ func testAccCheckSubnetGroupExists(ctx context.Context, n string) resource.TestC return fmt.Errorf("No MemoryDB Subnet Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindSubnetGroupByName(ctx, conn, rs.Primary.Attributes[names.AttrName]) diff --git a/internal/service/memorydb/sweep.go b/internal/service/memorydb/sweep.go index 7c751ef9a40..71a14d143b7 100644 --- a/internal/service/memorydb/sweep.go +++ b/internal/service/memorydb/sweep.go @@ -8,8 +8,9 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" @@ -68,7 +69,7 @@ func sweepACLs(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeACLsInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -78,7 +79,7 @@ func sweepACLs(region string) error { } for _, v := range page.ACLs { - id := aws.StringValue(v.Name) + id := aws.ToString(v.Name) if id == "open-access" { continue // The open-access ACL cannot be deleted. @@ -118,7 +119,7 @@ func sweepClusters(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeClustersInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -130,7 +131,7 @@ func sweepClusters(region string) error { for _, v := range page.Clusters { r := ResourceCluster() d := r.Data(nil) - d.SetId(aws.StringValue(v.Name)) + d.SetId(aws.ToString(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -162,7 +163,7 @@ func sweepParameterGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeParameterGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -172,7 +173,7 @@ func sweepParameterGroups(region string) error { } for _, v := range page.ParameterGroups { - id := aws.StringValue(v.Name) + id := aws.ToString(v.Name) if strings.HasPrefix(id, "default.") { continue // Default parameter groups cannot be deleted. @@ -180,7 +181,7 @@ func sweepParameterGroups(region string) error { r := ResourceParameterGroup() d := r.Data(nil) - d.SetId(aws.StringValue(v.Name)) + d.SetId(aws.ToString(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -212,7 +213,7 @@ func sweepSnapshots(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeSnapshotsInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -224,7 +225,7 @@ func sweepSnapshots(region string) error { for _, v := range page.Snapshots { r := ResourceSnapshot() d := r.Data(nil) - d.SetId(aws.StringValue(v.Name)) + d.SetId(aws.ToString(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -256,7 +257,7 @@ func sweepSubnetGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeSubnetGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -266,7 +267,7 @@ func sweepSubnetGroups(region string) error { } for _, v := range page.SubnetGroups { - id := aws.StringValue(v.Name) + id := aws.ToString(v.Name) if id == "default" { continue // The default subnet group cannot be deleted. @@ -306,7 +307,7 @@ func sweepUsers(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.MemoryDBConn(ctx) + conn := client.MemoryDBClient(ctx) input := &memorydb.DescribeUsersInput{} sweepResources := make([]sweep.Sweepable, 0) @@ -316,7 +317,7 @@ func sweepUsers(region string) error { } for _, v := range page.Users { - id := aws.StringValue(v.Name) + id := aws.ToString(v.Name) if id == "default" { continue // The default user cannot be deleted. diff --git a/internal/service/memorydb/user.go b/internal/service/memorydb/user.go index 688059531af..b553649ae36 100644 --- a/internal/service/memorydb/user.go +++ b/internal/service/memorydb/user.go @@ -7,13 +7,15 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/memorydb" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -71,7 +73,7 @@ func ResourceUser() *schema.Resource { names.AttrType: { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice(memorydb.InputAuthenticationType_Values(), false), + ValidateFunc: enum.Validate[awstypes.InputAuthenticationType](), }, }, }, @@ -95,7 +97,7 @@ func ResourceUser() *schema.Resource { func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) userName := d.Get(names.AttrUserName).(string) input := &memorydb.CreateUserInput{ @@ -108,7 +110,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf input.AuthenticationMode = expandAuthenticationMode(v.([]interface{})[0].(map[string]interface{})) } - _, err := conn.CreateUserWithContext(ctx, input) + _, err := conn.CreateUser(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MemoryDB User (%s): %s", userName, err) @@ -122,7 +124,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) user, err := FindUserByName(ctx, conn, d.Id()) @@ -142,8 +144,8 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac if v := user.Authentication; v != nil { authenticationMode := map[string]interface{}{ "passwords": d.Get("authentication_mode.0.passwords"), - "password_count": aws.Int64Value(v.PasswordCount), - names.AttrType: aws.StringValue(v.Type), + "password_count": aws.ToInt64(v.PasswordCount), + names.AttrType: aws.ToString(v.Type), } if err := d.Set("authentication_mode", []interface{}{authenticationMode}); err != nil { @@ -160,7 +162,7 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &memorydb.UpdateUserInput{ @@ -175,7 +177,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf input.AuthenticationMode = expandAuthenticationMode(v.([]interface{})[0].(map[string]interface{})) } - _, err := conn.UpdateUserWithContext(ctx, input) + _, err := conn.UpdateUser(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MemoryDB User (%s): %s", d.Id(), err) @@ -192,14 +194,14 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) log.Printf("[DEBUG] Deleting MemoryDB User: (%s)", d.Id()) - _, err := conn.DeleteUserWithContext(ctx, &memorydb.DeleteUserInput{ + _, err := conn.DeleteUser(ctx, &memorydb.DeleteUserInput{ UserName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, memorydb.ErrCodeUserNotFoundFault) { + if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeUserNotFoundFault) { return diags } @@ -214,12 +216,12 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interf return diags } -func expandAuthenticationMode(tfMap map[string]interface{}) *memorydb.AuthenticationMode { +func expandAuthenticationMode(tfMap map[string]interface{}) *awstypes.AuthenticationMode { if tfMap == nil { return nil } - apiObject := &memorydb.AuthenticationMode{} + apiObject := &awstypes.AuthenticationMode{} if v, ok := tfMap["passwords"].(*schema.Set); ok && v.Len() > 0 { apiObject.Passwords = flex.ExpandStringSet(v) diff --git a/internal/service/memorydb/user_data_source.go b/internal/service/memorydb/user_data_source.go index 28b962c60e7..8b898268de9 100644 --- a/internal/service/memorydb/user_data_source.go +++ b/internal/service/memorydb/user_data_source.go @@ -6,7 +6,7 @@ package memorydb import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -62,7 +62,7 @@ func DataSourceUser() *schema.Resource { func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MemoryDBConn(ctx) + conn := meta.(*conns.AWSClient).MemoryDBClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig userName := d.Get(names.AttrUserName).(string) @@ -73,15 +73,15 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interf return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MemoryDB User", err)) } - d.SetId(aws.StringValue(user.Name)) + d.SetId(aws.ToString(user.Name)) d.Set("access_string", user.AccessString) d.Set(names.AttrARN, user.ARN) if v := user.Authentication; v != nil { authenticationMode := map[string]interface{}{ - "password_count": aws.Int64Value(v.PasswordCount), - names.AttrType: aws.StringValue(v.Type), + "password_count": aws.ToInt64(v.PasswordCount), + names.AttrType: aws.ToString(v.Type), } if err := d.Set("authentication_mode", []interface{}{authenticationMode}); err != nil { diff --git a/internal/service/memorydb/user_test.go b/internal/service/memorydb/user_test.go index d839e02b182..2cffc0aa291 100644 --- a/internal/service/memorydb/user_test.go +++ b/internal/service/memorydb/user_test.go @@ -250,7 +250,7 @@ func TestAccMemoryDBUser_tags(t *testing.T) { func testAccCheckUserDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_memorydb_user" { @@ -285,7 +285,7 @@ func testAccCheckUserExists(ctx context.Context, n string) resource.TestCheckFun return fmt.Errorf("No MemoryDB User ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MemoryDBClient(ctx) _, err := tfmemorydb.FindUserByName(ctx, conn, rs.Primary.Attributes[names.AttrUserName]) diff --git a/internal/service/memorydb/wait.go b/internal/service/memorydb/wait.go index 1c98edd7580..910d202837a 100644 --- a/internal/service/memorydb/wait.go +++ b/internal/service/memorydb/wait.go @@ -7,7 +7,8 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/service/memorydb" + "github.com/aws/aws-sdk-go-v2/service/memorydb" + awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" ) @@ -30,7 +31,7 @@ const ( ) // waitACLActive waits for MemoryDB ACL to reach an active state after modifications. -func waitACLActive(ctx context.Context, conn *memorydb.MemoryDB, aclId string) error { +func waitACLActive(ctx context.Context, conn *memorydb.Client, aclId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{ACLStatusCreating, ACLStatusModifying}, Target: []string{ACLStatusActive}, @@ -44,7 +45,7 @@ func waitACLActive(ctx context.Context, conn *memorydb.MemoryDB, aclId string) e } // waitACLDeleted waits for MemoryDB ACL to be deleted. -func waitACLDeleted(ctx context.Context, conn *memorydb.MemoryDB, aclId string) error { +func waitACLDeleted(ctx context.Context, conn *memorydb.Client, aclId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{ACLStatusDeleting}, Target: []string{}, @@ -58,7 +59,7 @@ func waitACLDeleted(ctx context.Context, conn *memorydb.MemoryDB, aclId string) } // waitClusterAvailable waits for MemoryDB Cluster to reach an active state after modifications. -func waitClusterAvailable(ctx context.Context, conn *memorydb.MemoryDB, clusterId string, timeout time.Duration) error { +func waitClusterAvailable(ctx context.Context, conn *memorydb.Client, clusterId string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ Pending: []string{ClusterStatusCreating, ClusterStatusUpdating, ClusterStatusSnapshotting}, Target: []string{ClusterStatusAvailable}, @@ -72,7 +73,7 @@ func waitClusterAvailable(ctx context.Context, conn *memorydb.MemoryDB, clusterI } // waitClusterDeleted waits for MemoryDB Cluster to be deleted. -func waitClusterDeleted(ctx context.Context, conn *memorydb.MemoryDB, clusterId string, timeout time.Duration) error { +func waitClusterDeleted(ctx context.Context, conn *memorydb.Client, clusterId string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ Pending: []string{ClusterStatusDeleting}, Target: []string{}, @@ -87,7 +88,7 @@ func waitClusterDeleted(ctx context.Context, conn *memorydb.MemoryDB, clusterId // waitClusterParameterGroupInSync waits for MemoryDB Cluster to come in sync // with a new parameter group. -func waitClusterParameterGroupInSync(ctx context.Context, conn *memorydb.MemoryDB, clusterId string) error { +func waitClusterParameterGroupInSync(ctx context.Context, conn *memorydb.Client, clusterId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{ClusterParameterGroupStatusApplying}, Target: []string{ClusterParameterGroupStatusInSync}, @@ -102,7 +103,7 @@ func waitClusterParameterGroupInSync(ctx context.Context, conn *memorydb.MemoryD // waitClusterSecurityGroupsActive waits for MemoryDB Cluster to apply all // security group-related changes. -func waitClusterSecurityGroupsActive(ctx context.Context, conn *memorydb.MemoryDB, clusterId string) error { +func waitClusterSecurityGroupsActive(ctx context.Context, conn *memorydb.Client, clusterId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{ClusterSecurityGroupStatusModifying}, Target: []string{ClusterSecurityGroupStatusActive}, @@ -116,7 +117,7 @@ func waitClusterSecurityGroupsActive(ctx context.Context, conn *memorydb.MemoryD } // waitUserActive waits for MemoryDB user to reach an active state after modifications. -func waitUserActive(ctx context.Context, conn *memorydb.MemoryDB, userId string) error { +func waitUserActive(ctx context.Context, conn *memorydb.Client, userId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{UserStatusModifying}, Target: []string{UserStatusActive}, @@ -130,7 +131,7 @@ func waitUserActive(ctx context.Context, conn *memorydb.MemoryDB, userId string) } // waitUserDeleted waits for MemoryDB user to be deleted. -func waitUserDeleted(ctx context.Context, conn *memorydb.MemoryDB, userId string) error { +func waitUserDeleted(ctx context.Context, conn *memorydb.Client, userId string) error { stateConf := &retry.StateChangeConf{ Pending: []string{UserStatusDeleting}, Target: []string{}, @@ -144,7 +145,7 @@ func waitUserDeleted(ctx context.Context, conn *memorydb.MemoryDB, userId string } // waitSnapshotAvailable waits for MemoryDB snapshot to reach the available state. -func waitSnapshotAvailable(ctx context.Context, conn *memorydb.MemoryDB, snapshotId string, timeout time.Duration) error { +func waitSnapshotAvailable(ctx context.Context, conn *memorydb.Client, snapshotId string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ Pending: []string{SnapshotStatusCreating}, Target: []string{SnapshotStatusAvailable}, @@ -158,7 +159,7 @@ func waitSnapshotAvailable(ctx context.Context, conn *memorydb.MemoryDB, snapsho } // waitSnapshotDeleted waits for MemoryDB snapshot to be deleted. -func waitSnapshotDeleted(ctx context.Context, conn *memorydb.MemoryDB, snapshotId string, timeout time.Duration) error { +func waitSnapshotDeleted(ctx context.Context, conn *memorydb.Client, snapshotId string, timeout time.Duration) error { stateConf := &retry.StateChangeConf{ Pending: []string{SnapshotStatusDeleting}, Target: []string{}, From 17e57c653fcf017756da63d924ddf33228226566 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:02:49 +0100 Subject: [PATCH 04/10] d/memorydb_acl,r/memorydb_acl: Migrate to AWS SDK v2 --- internal/service/memorydb/acl.go | 16 ++++++++-------- internal/service/memorydb/acl_data_source.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/service/memorydb/acl.go b/internal/service/memorydb/acl.go index 17d91808418..e4777b96df8 100644 --- a/internal/service/memorydb/acl.go +++ b/internal/service/memorydb/acl.go @@ -10,13 +10,13 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -91,10 +91,10 @@ func resourceACLCreate(ctx context.Context, d *schema.ResourceData, meta interfa } if v, ok := d.GetOk("user_names"); ok && v.(*schema.Set).Len() > 0 { - input.UserNames = flex.ExpandStringSet(v.(*schema.Set)) + input.UserNames = flex.ExpandStringValueSet(v.(*schema.Set)) } - log.Printf("[DEBUG] Creating MemoryDB ACL: %s", input) + log.Printf("[DEBUG] Creating MemoryDB ACL: %+v", input) _, err := conn.CreateACL(ctx, input) if err != nil { @@ -124,7 +124,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa oldSet, newSet := o.(*schema.Set), n.(*schema.Set) if toAdd := newSet.Difference(oldSet); toAdd.Len() > 0 { - input.UserNamesToAdd = flex.ExpandStringSet(toAdd) + input.UserNamesToAdd = flex.ExpandStringValueSet(toAdd) } // When a user is deleted, MemoryDB will implicitly remove it from any @@ -141,7 +141,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa initialUserNames := map[string]struct{}{} for _, userName := range initialState.UserNames { - initialUserNames[aws.ToString(userName)] = struct{}{} + initialUserNames[userName] = struct{}{} } for _, v := range oldSet.Difference(newSet).List() { @@ -149,7 +149,7 @@ func resourceACLUpdate(ctx context.Context, d *schema.ResourceData, meta interfa _, userNameStillPresent := initialUserNames[userNameToRemove] if userNameStillPresent { - input.UserNamesToRemove = append(input.UserNamesToRemove, aws.String(userNameToRemove)) + input.UserNamesToRemove = append(input.UserNamesToRemove, userNameToRemove) } } @@ -191,7 +191,7 @@ func resourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface d.Set("minimum_engine_version", acl.MinimumEngineVersion) d.Set(names.AttrName, acl.Name) d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(acl.Name))) - d.Set("user_names", flex.FlattenStringSet(acl.UserNames)) + d.Set("user_names", flex.FlattenStringValueSet(acl.UserNames)) return diags } @@ -206,7 +206,7 @@ func resourceACLDelete(ctx context.Context, d *schema.ResourceData, meta interfa ACLName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeACLNotFoundFault) { + if errs.IsA[*awstypes.ACLNotFoundFault](err) { return diags } diff --git a/internal/service/memorydb/acl_data_source.go b/internal/service/memorydb/acl_data_source.go index ad6dd7b732b..909c55f62f2 100644 --- a/internal/service/memorydb/acl_data_source.go +++ b/internal/service/memorydb/acl_data_source.go @@ -64,7 +64,7 @@ func dataSourceACLRead(ctx context.Context, d *schema.ResourceData, meta interfa d.Set(names.AttrARN, acl.ARN) d.Set("minimum_engine_version", acl.MinimumEngineVersion) d.Set(names.AttrName, acl.Name) - d.Set("user_names", flex.FlattenStringSet(acl.UserNames)) + d.Set("user_names", flex.FlattenStringValueSet(acl.UserNames)) tags, err := listTags(ctx, conn, d.Get(names.AttrARN).(string)) From 4f26d2d52f2f7f6cce9b97fefd5953129401da49 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:09:35 +0100 Subject: [PATCH 05/10] d/memorydb_cluster,r/memorydb_cluster: Migrate to AWS SDK v2 --- internal/service/memorydb/cluster.go | 48 ++++++++----------- .../service/memorydb/cluster_data_source.go | 2 +- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/internal/service/memorydb/cluster.go b/internal/service/memorydb/cluster.go index ce2d4520a65..2949e693d06 100644 --- a/internal/service/memorydb/cluster.go +++ b/internal/service/memorydb/cluster.go @@ -13,13 +13,13 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -283,8 +283,8 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int AutoMinorVersionUpgrade: aws.Bool(d.Get(names.AttrAutoMinorVersionUpgrade).(bool)), ClusterName: aws.String(name), NodeType: aws.String(d.Get("node_type").(string)), - NumReplicasPerShard: aws.Int64(int64(d.Get("num_replicas_per_shard").(int))), - NumShards: aws.Int64(int64(d.Get("num_shards").(int))), + NumReplicasPerShard: aws.Int32(int32(d.Get("num_replicas_per_shard").(int))), + NumShards: aws.Int32(int32(d.Get("num_shards").(int))), Tags: getTagsIn(ctx), TLSEnabled: aws.Bool(d.Get("tls_enabled").(bool)), } @@ -314,16 +314,16 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk(names.AttrPort); ok { - input.Port = aws.Int64(int64(v.(int))) + input.Port = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk(names.AttrSecurityGroupIDs); ok { - input.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroupIds = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("snapshot_arns"); ok && len(v.([]interface{})) > 0 { v := v.([]interface{}) - input.SnapshotArns = flex.ExpandStringList(v) + input.SnapshotArns = flex.ExpandStringValueList(v) log.Printf("[DEBUG] Restoring MemoryDB Cluster (%s) from S3 snapshots %#v", name, v) } @@ -333,7 +333,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("snapshot_retention_limit"); ok { - input.SnapshotRetentionLimit = aws.Int64(int64(v.(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("snapshot_window"); ok { @@ -348,7 +348,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int input.SubnetGroupName = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating MemoryDB Cluster: %s", input) + log.Printf("[DEBUG] Creating MemoryDB Cluster: %+v", input) _, err := conn.CreateCluster(ctx, input) if err != nil { @@ -399,13 +399,13 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int if d.HasChange("num_replicas_per_shard") { input.ReplicaConfiguration = &awstypes.ReplicaConfigurationRequest{ - ReplicaCount: aws.Int64(int64(d.Get("num_replicas_per_shard").(int))), + ReplicaCount: int32(d.Get("num_replicas_per_shard").(int)), } } if d.HasChange("num_shards") { input.ShardConfiguration = &awstypes.ShardConfigurationRequest{ - ShardCount: aws.Int64(int64(d.Get("num_shards").(int))), + ShardCount: int32(d.Get("num_shards").(int)), } } @@ -425,12 +425,12 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "unable to update MemoryDB Cluster (%s): removing all security groups is not possible", d.Id()) } - input.SecurityGroupIds = flex.ExpandStringSet(v) + input.SecurityGroupIds = flex.ExpandStringValueSet(v) waitSecurityGroupsActive = true } if d.HasChange("snapshot_retention_limit") { - input.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(d.Get("snapshot_retention_limit").(int))) } if d.HasChange("snapshot_window") { @@ -502,7 +502,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrPort, v.Port) } - if v := aws.ToString(cluster.DataTiering); v != "" { + if v := string(cluster.DataTiering); v != "" { b, err := strconv.ParseBool(v) if err != nil { return sdkdiag.AppendErrorf(diags, "reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err) @@ -570,7 +570,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int log.Printf("[DEBUG] Deleting MemoryDB Cluster: (%s)", d.Id()) _, err := conn.DeleteCluster(ctx, input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeClusterNotFoundFault) { + if errs.IsA[*awstypes.ClusterNotFoundFault](err) { return diags } @@ -604,28 +604,20 @@ func flattenEndpoint(endpoint *awstypes.Endpoint) []interface{} { m[names.AttrAddress] = v } - if v := aws.ToInt64(endpoint.Port); v != 0 { - m[names.AttrPort] = v + if endpoint.Port != 0 { + m[names.AttrPort] = endpoint.Port } return []interface{}{m} } -func flattenShards(shards []*awstypes.Shard) *schema.Set { +func flattenShards(shards []awstypes.Shard) *schema.Set { shardSet := schema.NewSet(shardHash, nil) for _, shard := range shards { - if shard == nil { - continue - } - nodeSet := schema.NewSet(nodeHash, nil) for _, node := range shard.Nodes { - if node == nil { - continue - } - nodeSet.Add(map[string]interface{}{ names.AttrAvailabilityZone: aws.ToString(node.AvailabilityZone), names.AttrCreateTime: aws.ToTime(node.CreateTime).Format(time.RFC3339), @@ -636,7 +628,7 @@ func flattenShards(shards []*awstypes.Shard) *schema.Set { shardSet.Add(map[string]interface{}{ names.AttrName: aws.ToString(shard.Name), - "num_nodes": int(aws.ToInt64(shard.NumberOfNodes)), + "num_nodes": int(aws.ToInt32(shard.NumberOfNodes)), "nodes": nodeSet, "slots": aws.ToString(shard.Slots), }) @@ -651,14 +643,14 @@ func flattenShards(shards []*awstypes.Shard) *schema.Set { // // For the sake of caution, this search is limited to stable shards. func deriveClusterNumReplicasPerShard(cluster *awstypes.Cluster) (int, error) { - var maxNumberOfNodesPerShard int64 + var maxNumberOfNodesPerShard int32 for _, shard := range cluster.Shards { if aws.ToString(shard.Status) != ClusterShardStatusAvailable { continue } - n := aws.ToInt64(shard.NumberOfNodes) + n := aws.ToInt32(shard.NumberOfNodes) if n > maxNumberOfNodesPerShard { maxNumberOfNodesPerShard = n } diff --git a/internal/service/memorydb/cluster_data_source.go b/internal/service/memorydb/cluster_data_source.go index 9d3f58dd4e0..723868a19a5 100644 --- a/internal/service/memorydb/cluster_data_source.go +++ b/internal/service/memorydb/cluster_data_source.go @@ -189,7 +189,7 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set(names.AttrPort, v.Port) } - if v := aws.ToString(cluster.DataTiering); v != "" { + if v := string(cluster.DataTiering); v != "" { b, err := strconv.ParseBool(v) if err != nil { return sdkdiag.AppendErrorf(diags, "reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err) From 93cc45486c020e70d2bfd59de6ab4746bef1630d Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:19:57 +0100 Subject: [PATCH 06/10] r/memorydb_parameter_group: Migrate to AWS SDK v2 --- internal/service/memorydb/parameter_group.go | 23 ++++++++++--------- .../service/memorydb/parameter_group_test.go | 1 - 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/service/memorydb/parameter_group.go b/internal/service/memorydb/parameter_group.go index 883c435d84e..bb5a2aa1401 100644 --- a/internal/service/memorydb/parameter_group.go +++ b/internal/service/memorydb/parameter_group.go @@ -14,14 +14,15 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "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/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -111,7 +112,7 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m Tags: getTagsIn(ctx), } - log.Printf("[DEBUG] Creating MemoryDB Parameter Group: %s", input) + log.Printf("[DEBUG] Creating MemoryDB Parameter Group: %+v", input) output, err := conn.CreateParameterGroup(ctx, input) if err != nil { @@ -227,7 +228,7 @@ func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, m ParameterGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeParameterGroupNotFoundFault) { + if errs.IsA[*awstypes.ParameterGroupNotFoundFault](err) { return diags } @@ -240,9 +241,9 @@ func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, m // resetParameterGroupParameters resets the given parameters to their default values. func resetParameterGroupParameters(ctx context.Context, conn *memorydb.Client, name string, parameters []*awstypes.ParameterNameValue) error { - var parameterNames []*string + var parameterNames []string for _, parameter := range parameters { - parameterNames = append(parameterNames, parameter.ParameterName) + parameterNames = append(parameterNames, *parameter.ParameterName) } input := memorydb.ResetParameterGroupInput{ @@ -253,7 +254,7 @@ func resetParameterGroupParameters(ctx context.Context, conn *memorydb.Client, n return retry.RetryContext(ctx, 30*time.Second, func() *retry.RetryError { _, err := conn.ResetParameterGroup(ctx, &input) if err != nil { - if tfawserr.ErrMessageContains(err, awstypes.ErrCodeInvalidParameterGroupStateFault, " has pending changes") { + if errs.IsAErrorMessageContains[*awstypes.InvalidParameterGroupStateFault](err, " has pending changes") { return retry.RetryableError(err) } return retry.NonRetryableError(err) @@ -266,7 +267,7 @@ func resetParameterGroupParameters(ctx context.Context, conn *memorydb.Client, n func modifyParameterGroupParameters(ctx context.Context, conn *memorydb.Client, name string, parameters []*awstypes.ParameterNameValue) error { input := memorydb.UpdateParameterGroupInput{ ParameterGroupName: aws.String(name), - ParameterNameValues: parameters, + ParameterNameValues: tfslices.Values(parameters), } _, err := conn.UpdateParameterGroup(ctx, &input) return err @@ -277,8 +278,8 @@ func modifyParameterGroupParameters(ctx context.Context, conn *memorydb.Client, // // Parameters given in userDefined will be returned even if the value is equal // to the default. -func listParameterGroupParameters(ctx context.Context, conn *memorydb.Client, family, name string, userDefined map[string]string) ([]*awstypes.Parameter, error) { - query := func(ctx context.Context, parameterGroupName string) ([]*awstypes.Parameter, error) { +func listParameterGroupParameters(ctx context.Context, conn *memorydb.Client, family, name string, userDefined map[string]string) ([]awstypes.Parameter, error) { + query := func(ctx context.Context, parameterGroupName string) ([]awstypes.Parameter, error) { input := memorydb.DescribeParametersInput{ ParameterGroupName: aws.String(parameterGroupName), } @@ -311,7 +312,7 @@ func listParameterGroupParameters(ctx context.Context, conn *memorydb.Client, fa return nil, err } - var result []*awstypes.Parameter + var result []awstypes.Parameter for _, parameter := range current { name := aws.ToString(parameter.Name) @@ -380,7 +381,7 @@ func ParameterChanges(o, n interface{}) (remove, addOrUpdate []*awstypes.Paramet return remove, addOrUpdate } -func flattenParameters(list []*awstypes.Parameter) []map[string]interface{} { +func flattenParameters(list []awstypes.Parameter) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { if i.Value != nil { diff --git a/internal/service/memorydb/parameter_group_test.go b/internal/service/memorydb/parameter_group_test.go index 2a3409c18a0..2775481eecc 100644 --- a/internal/service/memorydb/parameter_group_test.go +++ b/internal/service/memorydb/parameter_group_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" From c4d0b6ec560c75fee3af36f6bba03cda0d9de75e Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:22:10 +0100 Subject: [PATCH 07/10] r/memorydb_snapshot: Migrate to AWS SDK v2 --- internal/service/memorydb/snapshot.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/memorydb/snapshot.go b/internal/service/memorydb/snapshot.go index 7443f021fea..49d49d6de0f 100644 --- a/internal/service/memorydb/snapshot.go +++ b/internal/service/memorydb/snapshot.go @@ -10,12 +10,12 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -165,7 +165,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, meta in input.KmsKeyId = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating MemoryDB Snapshot: %s", input) + log.Printf("[DEBUG] Creating MemoryDB Snapshot: %+v", input) _, err := conn.CreateSnapshot(ctx, input) if err != nil { @@ -226,7 +226,7 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, meta in SnapshotName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSnapshotNotFoundFault) { + if errs.IsA[*awstypes.SnapshotNotFoundFault](err) { return diags } @@ -252,10 +252,10 @@ func flattenClusterConfiguration(v *awstypes.ClusterConfiguration) []interface{} "maintenance_window": aws.ToString(v.MaintenanceWindow), names.AttrName: aws.ToString(v.Name), "node_type": aws.ToString(v.NodeType), - "num_shards": aws.ToInt64(v.NumShards), + "num_shards": aws.ToInt32(v.NumShards), names.AttrParameterGroupName: aws.ToString(v.ParameterGroupName), - names.AttrPort: aws.ToInt64(v.Port), - "snapshot_retention_limit": aws.ToInt64(v.SnapshotRetentionLimit), + names.AttrPort: aws.ToInt32(v.Port), + "snapshot_retention_limit": aws.ToInt32(v.SnapshotRetentionLimit), "snapshot_window": aws.ToString(v.SnapshotWindow), "subnet_group_name": aws.ToString(v.SubnetGroupName), names.AttrTopicARN: aws.ToString(v.TopicArn), From b8bb9f57449e63d4b2bba8690af9430cbc420a90 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:23:23 +0100 Subject: [PATCH 08/10] r/memorydb_subnet_group: Migrate to AWS SDK v2 --- internal/service/memorydb/subnet_group.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/memorydb/subnet_group.go b/internal/service/memorydb/subnet_group.go index 891bd7c5647..e0793679f83 100644 --- a/internal/service/memorydb/subnet_group.go +++ b/internal/service/memorydb/subnet_group.go @@ -10,12 +10,12 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -90,11 +90,11 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta input := &memorydb.CreateSubnetGroupInput{ Description: aws.String(d.Get(names.AttrDescription).(string)), SubnetGroupName: aws.String(name), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), Tags: getTagsIn(ctx), } - log.Printf("[DEBUG] Creating MemoryDB Subnet Group: %s", input) + log.Printf("[DEBUG] Creating MemoryDB Subnet Group: %+v", input) _, err := conn.CreateSubnetGroup(ctx, input) if err != nil { @@ -115,10 +115,10 @@ func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta input := &memorydb.UpdateSubnetGroupInput{ Description: aws.String(d.Get(names.AttrDescription).(string)), SubnetGroupName: aws.String(d.Id()), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), } - log.Printf("[DEBUG] Updating MemoryDB Subnet Group: %s", input) + log.Printf("[DEBUG] Updating MemoryDB Subnet Group: %+v", input) _, err := conn.UpdateSubnetGroup(ctx, input) if err != nil { @@ -171,7 +171,7 @@ func resourceSubnetGroupDelete(ctx context.Context, d *schema.ResourceData, meta SubnetGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSubnetGroupNotFoundFault) { + if errs.IsA[*awstypes.SubnetGroupNotFoundFault](err) { return diags } From 3339459274e36e276c2daa2c20b7049bac6ef436 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:24:23 +0100 Subject: [PATCH 09/10] d/memorydb_user,r/memorydb_user: Migrate to AWS SDK v2 --- internal/service/memorydb/user.go | 18 +++++++++--------- internal/service/memorydb/user_data_source.go | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/service/memorydb/user.go b/internal/service/memorydb/user.go index b553649ae36..74625a8a71a 100644 --- a/internal/service/memorydb/user.go +++ b/internal/service/memorydb/user.go @@ -10,12 +10,12 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/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/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -71,9 +71,9 @@ func ResourceUser() *schema.Resource { Computed: true, }, names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateFunc: enum.Validate[awstypes.InputAuthenticationType](), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.InputAuthenticationType](), }, }, }, @@ -144,8 +144,8 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac if v := user.Authentication; v != nil { authenticationMode := map[string]interface{}{ "passwords": d.Get("authentication_mode.0.passwords"), - "password_count": aws.ToInt64(v.PasswordCount), - names.AttrType: aws.ToString(v.Type), + "password_count": aws.ToInt32(v.PasswordCount), + names.AttrType: string(v.Type), } if err := d.Set("authentication_mode", []interface{}{authenticationMode}); err != nil { @@ -201,7 +201,7 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interf UserName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeUserNotFoundFault) { + if errs.IsA[*awstypes.UserNotFoundFault](err) { return diags } @@ -224,11 +224,11 @@ func expandAuthenticationMode(tfMap map[string]interface{}) *awstypes.Authentica apiObject := &awstypes.AuthenticationMode{} if v, ok := tfMap["passwords"].(*schema.Set); ok && v.Len() > 0 { - apiObject.Passwords = flex.ExpandStringSet(v) + apiObject.Passwords = flex.ExpandStringValueSet(v) } if v, ok := tfMap[names.AttrType].(string); ok && v != "" { - apiObject.Type = aws.String(v) + apiObject.Type = awstypes.InputAuthenticationType(v) } return apiObject diff --git a/internal/service/memorydb/user_data_source.go b/internal/service/memorydb/user_data_source.go index 8b898268de9..9cf99f7446c 100644 --- a/internal/service/memorydb/user_data_source.go +++ b/internal/service/memorydb/user_data_source.go @@ -80,8 +80,8 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interf if v := user.Authentication; v != nil { authenticationMode := map[string]interface{}{ - "password_count": aws.ToInt64(v.PasswordCount), - names.AttrType: aws.ToString(v.Type), + "password_count": aws.ToInt32(v.PasswordCount), + names.AttrType: string(v.Type), } if err := d.Set("authentication_mode", []interface{}{authenticationMode}); err != nil { From 654296a53bfde4302023061ffe14a924fea27802 Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:33:04 +0100 Subject: [PATCH 10/10] memorydb: misc: Migrate to AWS SDK v2 --- internal/service/memorydb/find.go | 74 +++++------------------------ internal/service/memorydb/status.go | 1 - internal/service/memorydb/sweep.go | 1 - internal/service/memorydb/wait.go | 1 - 4 files changed, 13 insertions(+), 64 deletions(-) diff --git a/internal/service/memorydb/find.go b/internal/service/memorydb/find.go index 6d6c6e3f534..d99be4281ec 100644 --- a/internal/service/memorydb/find.go +++ b/internal/service/memorydb/find.go @@ -9,8 +9,8 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" - "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" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -21,7 +21,7 @@ func FindACLByName(ctx context.Context, conn *memorydb.Client, name string) (*aw output, err := conn.DescribeACLs(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeACLNotFoundFault) { + if errs.IsA[*awstypes.ACLNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -32,15 +32,7 @@ func FindACLByName(ctx context.Context, conn *memorydb.Client, name string) (*aw return nil, err } - if output == nil || len(output.ACLs) == 0 || output.ACLs[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.ACLs); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.ACLs[0], nil + return tfresource.AssertSingleValueResult(output.ACLs) } func FindClusterByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.Cluster, error) { @@ -51,7 +43,7 @@ func FindClusterByName(ctx context.Context, conn *memorydb.Client, name string) output, err := conn.DescribeClusters(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeClusterNotFoundFault) { + if errs.IsA[*awstypes.ClusterNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -62,15 +54,7 @@ func FindClusterByName(ctx context.Context, conn *memorydb.Client, name string) return nil, err } - if output == nil || len(output.Clusters) == 0 || output.Clusters[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.Clusters); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.Clusters[0], nil + return tfresource.AssertSingleValueResult(output.Clusters) } func FindParameterGroupByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.ParameterGroup, error) { @@ -80,7 +64,7 @@ func FindParameterGroupByName(ctx context.Context, conn *memorydb.Client, name s output, err := conn.DescribeParameterGroups(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeParameterGroupNotFoundFault) { + if errs.IsA[*awstypes.ParameterGroupNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -91,15 +75,7 @@ func FindParameterGroupByName(ctx context.Context, conn *memorydb.Client, name s return nil, err } - if output == nil || len(output.ParameterGroups) == 0 || output.ParameterGroups[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.ParameterGroups); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.ParameterGroups[0], nil + return tfresource.AssertSingleValueResult(output.ParameterGroups) } func FindSnapshotByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.Snapshot, error) { @@ -109,7 +85,7 @@ func FindSnapshotByName(ctx context.Context, conn *memorydb.Client, name string) output, err := conn.DescribeSnapshots(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSnapshotNotFoundFault) { + if errs.IsA[*awstypes.SnapshotNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -120,15 +96,7 @@ func FindSnapshotByName(ctx context.Context, conn *memorydb.Client, name string) return nil, err } - if output == nil || len(output.Snapshots) == 0 || output.Snapshots[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.Snapshots); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.Snapshots[0], nil + return tfresource.AssertSingleValueResult(output.Snapshots) } func FindSubnetGroupByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.SubnetGroup, error) { @@ -138,7 +106,7 @@ func FindSubnetGroupByName(ctx context.Context, conn *memorydb.Client, name stri output, err := conn.DescribeSubnetGroups(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeSubnetGroupNotFoundFault) { + if errs.IsA[*awstypes.SubnetGroupNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -149,15 +117,7 @@ func FindSubnetGroupByName(ctx context.Context, conn *memorydb.Client, name stri return nil, err } - if output == nil || len(output.SubnetGroups) == 0 || output.SubnetGroups[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.SubnetGroups); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.SubnetGroups[0], nil + return tfresource.AssertSingleValueResult(output.SubnetGroups) } func FindUserByName(ctx context.Context, conn *memorydb.Client, name string) (*awstypes.User, error) { @@ -167,7 +127,7 @@ func FindUserByName(ctx context.Context, conn *memorydb.Client, name string) (*a output, err := conn.DescribeUsers(ctx, &input) - if tfawserr.ErrCodeEquals(err, awstypes.ErrCodeUserNotFoundFault) { + if errs.IsA[*awstypes.UserNotFoundFault](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -178,13 +138,5 @@ func FindUserByName(ctx context.Context, conn *memorydb.Client, name string) (*a return nil, err } - if output == nil || len(output.Users) == 0 || output.Users[0] == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if count := len(output.Users); count > 1 { - return nil, tfresource.NewTooManyResultsError(count, input) - } - - return output.Users[0], nil + return tfresource.AssertSingleValueResult(output.Users) } diff --git a/internal/service/memorydb/status.go b/internal/service/memorydb/status.go index b72718f38d0..30ded7af769 100644 --- a/internal/service/memorydb/status.go +++ b/internal/service/memorydb/status.go @@ -8,7 +8,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" - awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) diff --git a/internal/service/memorydb/sweep.go b/internal/service/memorydb/sweep.go index 71a14d143b7..4b25950c987 100644 --- a/internal/service/memorydb/sweep.go +++ b/internal/service/memorydb/sweep.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/memorydb" - awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" diff --git a/internal/service/memorydb/wait.go b/internal/service/memorydb/wait.go index 910d202837a..b546a885833 100644 --- a/internal/service/memorydb/wait.go +++ b/internal/service/memorydb/wait.go @@ -8,7 +8,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/service/memorydb" - awstypes "github.com/aws/aws-sdk-go-v2/service/memorydb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" )