From 346ed900ef68f9a9685d31aaf68b98d40d464b16 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:02:09 -0400 Subject: [PATCH 01/13] Use AWS SDK for Go v2 for keyspaces service. --- names/names_data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/names/names_data.csv b/names/names_data.csv index 5ccb17659b91..9771d23fa7ec 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -199,7 +199,7 @@ iotwireless,iotwireless,iotwireless,iotwireless,,iotwireless,,,IoTWireless,IoTWi ivs,ivs,ivs,ivs,,ivs,,,IVS,IVS,,1,,,aws_ivs_,,ivs_,IVS (Interactive Video),Amazon,,,,, ivschat,ivschat,ivschat,ivschat,,ivschat,,,IVSChat,Ivschat,,,2,,aws_ivschat_,,ivschat_,IVS (Interactive Video) Chat,Amazon,,,,, kendra,kendra,kendra,kendra,,kendra,,,Kendra,Kendra,,,2,,aws_kendra_,,kendra_,Kendra,Amazon,,,,, -keyspaces,keyspaces,keyspaces,,,keyspaces,,,Keyspaces,Keyspaces,,1,,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, +keyspaces,keyspaces,keyspaces,,,keyspaces,,,Keyspaces,Keyspaces,,,2,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, kinesis,kinesis,kinesis,kinesis,,kinesis,,,Kinesis,Kinesis,,1,,aws_kinesis_stream,aws_kinesis_,,kinesis_stream,Kinesis,Amazon,,,,, kinesisanalytics,kinesisanalytics,kinesisanalytics,kinesisanalytics,,kinesisanalytics,,,KinesisAnalytics,KinesisAnalytics,,1,,aws_kinesis_analytics_,aws_kinesisanalytics_,,kinesis_analytics_,Kinesis Analytics,Amazon,,,,, kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,,kinesisanalyticsv2,,,KinesisAnalyticsV2,KinesisAnalyticsV2,,1,,,aws_kinesisanalyticsv2_,,kinesisanalyticsv2_,Kinesis Analytics V2,Amazon,,,,, From c78eacb3b22789a87ab1cae5ea2489280a93813a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:03:19 -0400 Subject: [PATCH 02/13] Add 'names.KeyspacesEndpointID. --- names/names.go | 1 + 1 file changed, 1 insertion(+) diff --git a/names/names.go b/names/names.go index ec8eec41b18f..201b2533c9b8 100644 --- a/names/names.go +++ b/names/names.go @@ -35,6 +35,7 @@ const ( Inspector2EndpointID = "inspector2" IVSChatEndpointID = "ivschat" KendraEndpointID = "kendra" + KeyspacesEndpointID = "keyspaces" LambdaEndpointID = "lambda" MediaLiveEndpointID = "medialive" ObservabilityAccessManagerEndpointID = "oam" From fbbdacf67424b5e3c448c1ced7133b90967de64d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:04:45 -0400 Subject: [PATCH 03/13] keyspaces: Generate AWS SDK for Go v2 tagging code. --- internal/service/keyspaces/generate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/keyspaces/generate.go b/internal/service/keyspaces/generate.go index 1f32f30768bd..a263d7fee0f2 100644 --- a/internal/service/keyspaces/generate.go +++ b/internal/service/keyspaces/generate.go @@ -1,4 +1,4 @@ -//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsSlice -UpdateTags -UntagInTagsElem=Tags -UntagInNeedTagType +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ServiceTagsSlice -UpdateTags -UntagInTagsElem=Tags -UntagInNeedTagType //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. From bfa3f745124695725637bc157828e374efeb2471 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:10:46 -0400 Subject: [PATCH 04/13] Revert "Use AWS SDK for Go v2 for keyspaces service." This reverts commit 346ed900ef68f9a9685d31aaf68b98d40d464b16. --- names/names_data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/names/names_data.csv b/names/names_data.csv index 9771d23fa7ec..5ccb17659b91 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -199,7 +199,7 @@ iotwireless,iotwireless,iotwireless,iotwireless,,iotwireless,,,IoTWireless,IoTWi ivs,ivs,ivs,ivs,,ivs,,,IVS,IVS,,1,,,aws_ivs_,,ivs_,IVS (Interactive Video),Amazon,,,,, ivschat,ivschat,ivschat,ivschat,,ivschat,,,IVSChat,Ivschat,,,2,,aws_ivschat_,,ivschat_,IVS (Interactive Video) Chat,Amazon,,,,, kendra,kendra,kendra,kendra,,kendra,,,Kendra,Kendra,,,2,,aws_kendra_,,kendra_,Kendra,Amazon,,,,, -keyspaces,keyspaces,keyspaces,,,keyspaces,,,Keyspaces,Keyspaces,,,2,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, +keyspaces,keyspaces,keyspaces,,,keyspaces,,,Keyspaces,Keyspaces,,1,,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, kinesis,kinesis,kinesis,kinesis,,kinesis,,,Kinesis,Kinesis,,1,,aws_kinesis_stream,aws_kinesis_,,kinesis_stream,Kinesis,Amazon,,,,, kinesisanalytics,kinesisanalytics,kinesisanalytics,kinesisanalytics,,kinesisanalytics,,,KinesisAnalytics,KinesisAnalytics,,1,,aws_kinesis_analytics_,aws_kinesisanalytics_,,kinesis_analytics_,Kinesis Analytics,Amazon,,,,, kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,,kinesisanalyticsv2,,,KinesisAnalyticsV2,KinesisAnalyticsV2,,1,,,aws_kinesisanalyticsv2_,,kinesisanalyticsv2_,Kinesis Analytics V2,Amazon,,,,, From da587c9590fd141472cf53862365cf6bfdaa9efd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:17:02 -0400 Subject: [PATCH 05/13] Use AWS SDK for Go v2 for keyspaces service. --- names/names_data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/names/names_data.csv b/names/names_data.csv index 5ccb17659b91..1c9ffb5bffe9 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -199,7 +199,7 @@ iotwireless,iotwireless,iotwireless,iotwireless,,iotwireless,,,IoTWireless,IoTWi ivs,ivs,ivs,ivs,,ivs,,,IVS,IVS,,1,,,aws_ivs_,,ivs_,IVS (Interactive Video),Amazon,,,,, ivschat,ivschat,ivschat,ivschat,,ivschat,,,IVSChat,Ivschat,,,2,,aws_ivschat_,,ivschat_,IVS (Interactive Video) Chat,Amazon,,,,, kendra,kendra,kendra,kendra,,kendra,,,Kendra,Kendra,,,2,,aws_kendra_,,kendra_,Kendra,Amazon,,,,, -keyspaces,keyspaces,keyspaces,,,keyspaces,,,Keyspaces,Keyspaces,,1,,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, +keyspaces,keyspaces,keyspaces,keyspaces,,keyspaces,,,Keyspaces,Keyspaces,,,2,,aws_keyspaces_,,keyspaces_,Keyspaces (for Apache Cassandra),Amazon,,,,, kinesis,kinesis,kinesis,kinesis,,kinesis,,,Kinesis,Kinesis,,1,,aws_kinesis_stream,aws_kinesis_,,kinesis_stream,Kinesis,Amazon,,,,, kinesisanalytics,kinesisanalytics,kinesisanalytics,kinesisanalytics,,kinesisanalytics,,,KinesisAnalytics,KinesisAnalytics,,1,,aws_kinesis_analytics_,aws_kinesisanalytics_,,kinesis_analytics_,Kinesis Analytics,Amazon,,,,, kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,kinesisanalyticsv2,,kinesisanalyticsv2,,,KinesisAnalyticsV2,KinesisAnalyticsV2,,1,,,aws_kinesisanalyticsv2_,,kinesisanalyticsv2_,Kinesis Analytics V2,Amazon,,,,, From 4e94d3a5a99c5e65a9c4aac87befb4d19a046a64 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:17:10 -0400 Subject: [PATCH 06/13] Run 'make gen'. --- internal/conns/awsclient_gen.go | 6 ++-- .../service/keyspaces/service_package_gen.go | 17 ++++++---- internal/service/keyspaces/tags_gen.go | 34 +++++++++---------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 2d8fe14ee151..c2b329ce4aaa 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -25,6 +25,7 @@ import ( inspector2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/inspector2" ivschat_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ivschat" kendra_sdkv2 "github.com/aws/aws-sdk-go-v2/service/kendra" + keyspaces_sdkv2 "github.com/aws/aws-sdk-go-v2/service/keyspaces" lambda_sdkv2 "github.com/aws/aws-sdk-go-v2/service/lambda" lightsail_sdkv2 "github.com/aws/aws-sdk-go-v2/service/lightsail" medialive_sdkv2 "github.com/aws/aws-sdk-go-v2/service/medialive" @@ -193,7 +194,6 @@ import ( ivs_sdkv1 "github.com/aws/aws-sdk-go/service/ivs" kafka_sdkv1 "github.com/aws/aws-sdk-go/service/kafka" kafkaconnect_sdkv1 "github.com/aws/aws-sdk-go/service/kafkaconnect" - keyspaces_sdkv1 "github.com/aws/aws-sdk-go/service/keyspaces" kinesis_sdkv1 "github.com/aws/aws-sdk-go/service/kinesis" kinesisanalytics_sdkv1 "github.com/aws/aws-sdk-go/service/kinesisanalytics" kinesisanalyticsv2_sdkv1 "github.com/aws/aws-sdk-go/service/kinesisanalyticsv2" @@ -984,8 +984,8 @@ func (c *AWSClient) KendraClient(ctx context.Context) *kendra_sdkv2.Client { return errs.Must(client[*kendra_sdkv2.Client](ctx, c, names.Kendra)) } -func (c *AWSClient) KeyspacesConn(ctx context.Context) *keyspaces_sdkv1.Keyspaces { - return errs.Must(conn[*keyspaces_sdkv1.Keyspaces](ctx, c, names.Keyspaces)) +func (c *AWSClient) KeyspacesClient(ctx context.Context) *keyspaces_sdkv2.Client { + return errs.Must(client[*keyspaces_sdkv2.Client](ctx, c, names.Keyspaces)) } func (c *AWSClient) KinesisConn(ctx context.Context) *kinesis_sdkv1.Kinesis { diff --git a/internal/service/keyspaces/service_package_gen.go b/internal/service/keyspaces/service_package_gen.go index 00e73069e508..076826d26924 100644 --- a/internal/service/keyspaces/service_package_gen.go +++ b/internal/service/keyspaces/service_package_gen.go @@ -5,9 +5,8 @@ package keyspaces import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - keyspaces_sdkv1 "github.com/aws/aws-sdk-go/service/keyspaces" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + keyspaces_sdkv2 "github.com/aws/aws-sdk-go-v2/service/keyspaces" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -52,11 +51,15 @@ func (p *servicePackage) ServicePackageName() string { return names.Keyspaces } -// 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) (*keyspaces_sdkv1.Keyspaces, error) { - sess := config["session"].(*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) (*keyspaces_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return keyspaces_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return keyspaces_sdkv2.NewFromConfig(cfg, func(o *keyspaces_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.EndpointResolver = keyspaces_sdkv2.EndpointResolverFromURL(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/keyspaces/tags_gen.go b/internal/service/keyspaces/tags_gen.go index d4d03a5f2baa..d736dc85d156 100644 --- a/internal/service/keyspaces/tags_gen.go +++ b/internal/service/keyspaces/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" - "github.com/aws/aws-sdk-go/service/keyspaces/keyspacesiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/keyspaces" + awstypes "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" "github.com/hashicorp/terraform-provider-aws/internal/conns" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/types" @@ -17,12 +17,12 @@ import ( // listTags lists keyspaces 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 keyspacesiface.KeyspacesAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *keyspaces.Client, identifier string) (tftags.KeyValueTags, error) { input := &keyspaces.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input) if err != nil { return tftags.New(ctx, nil), err @@ -34,7 +34,7 @@ func listTags(ctx context.Context, conn keyspacesiface.KeyspacesAPI, identifier // ListTags lists keyspaces 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).KeyspacesConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).KeyspacesClient(ctx), identifier) if err != nil { return err @@ -50,11 +50,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // Tags returns keyspaces service tags. -func Tags(tags tftags.KeyValueTags) []*keyspaces.Tag { - result := make([]*keyspaces.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 := &keyspaces.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -66,11 +66,11 @@ func Tags(tags tftags.KeyValueTags) []*keyspaces.Tag { } // KeyValueTags creates tftags.KeyValueTags from keyspaces service tags. -func KeyValueTags(ctx context.Context, tags []*keyspaces.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) @@ -78,7 +78,7 @@ func KeyValueTags(ctx context.Context, tags []*keyspaces.Tag) tftags.KeyValueTag // getTagsIn returns keyspaces service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*keyspaces.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 @@ -89,7 +89,7 @@ func getTagsIn(ctx context.Context) []*keyspaces.Tag { } // setTagsOut sets keyspaces service tags in Context. -func setTagsOut(ctx context.Context, tags []*keyspaces.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = types.Some(KeyValueTags(ctx, tags)) } @@ -98,7 +98,7 @@ func setTagsOut(ctx context.Context, tags []*keyspaces.Tag) { // updateTags updates keyspaces 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 keyspacesiface.KeyspacesAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *keyspaces.Client, identifier string, oldTagsMap, newTagsMap any) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -110,7 +110,7 @@ func updateTags(ctx context.Context, conn keyspacesiface.KeyspacesAPI, identifie Tags: Tags(removedTags), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -125,7 +125,7 @@ func updateTags(ctx context.Context, conn keyspacesiface.KeyspacesAPI, identifie Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -138,5 +138,5 @@ func updateTags(ctx context.Context, conn keyspacesiface.KeyspacesAPI, identifie // UpdateTags updates keyspaces 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).KeyspacesConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).KeyspacesClient(ctx), identifier, oldTags, newTags) } From bf04974465b78a8607b0f4736c9fc0706c9d0d6c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:18:12 -0400 Subject: [PATCH 07/13] Run 'go get github.com/aws/aws-sdk-go-v2/service/keyspaces@v1.3.2 && go mod tidy'. --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index 1b0dfceef8b3..41c733629711 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/inspector2 v1.15.0 github.com/aws/aws-sdk-go-v2/service/ivschat v1.4.7 github.com/aws/aws-sdk-go-v2/service/kendra v1.41.0 + github.com/aws/aws-sdk-go-v2/service/keyspaces v1.3.2 github.com/aws/aws-sdk-go-v2/service/lambda v1.37.0 github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.1 github.com/aws/aws-sdk-go-v2/service/medialive v1.31.6 diff --git a/go.sum b/go.sum index 2cf7bfc73c35..f7d85ed09786 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/aws/aws-sdk-go-v2/service/ivschat v1.4.7 h1:pI950CQHVEFW2/+UklRO4TWzH github.com/aws/aws-sdk-go-v2/service/ivschat v1.4.7/go.mod h1:oOLFrfP14cyQdTsc3I8VohdYb8g86I7xduoMALyKLj0= github.com/aws/aws-sdk-go-v2/service/kendra v1.41.0 h1:QZIaiIYfU8KCUuT4nCif9fifXryv+/pI/ounZMB4/0s= github.com/aws/aws-sdk-go-v2/service/kendra v1.41.0/go.mod h1:huU0BQC+O9qcc3vrANhwkC9KP0hGg1quffiyfbJ1Ktg= +github.com/aws/aws-sdk-go-v2/service/keyspaces v1.3.2 h1:nL5UBozBBCgCV5nv03YvDnuuCH11iI4pNjH/EchcBEU= +github.com/aws/aws-sdk-go-v2/service/keyspaces v1.3.2/go.mod h1:kce6B9bwqIlk810LDwZC4bT928MQc9c88OtXkqGIymc= github.com/aws/aws-sdk-go-v2/service/lambda v1.37.0 h1:xzyM5ZR9kZW0/Bkw5EiihOy6B+BYclp5K+yb6OHjc7s= github.com/aws/aws-sdk-go-v2/service/lambda v1.37.0/go.mod h1:Q8zQi5nZpjUF/H55dKEpKfEvFWJkgZzjjqvDb2AR5b4= github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.1 h1:q9YZIsBPkeafzYPAJUquHZW5WkdmsLLu4jWlWzNEyjI= From 07de08eaf90fcd8ed86b593df746a8abc51fd3bd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:27:33 -0400 Subject: [PATCH 08/13] r/aws_keyspaces_keyspace: Migrate to AWS SDK for Go v2. --- internal/service/keyspaces/exports_test.go | 8 +++ internal/service/keyspaces/find.go | 25 -------- internal/service/keyspaces/keyspace.go | 57 ++++++++++++++----- .../service/keyspaces/service_package_gen.go | 2 +- 4 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 internal/service/keyspaces/exports_test.go diff --git a/internal/service/keyspaces/exports_test.go b/internal/service/keyspaces/exports_test.go new file mode 100644 index 000000000000..649cdf379d14 --- /dev/null +++ b/internal/service/keyspaces/exports_test.go @@ -0,0 +1,8 @@ +package keyspaces + +// Exports for use in tests only. +var ( + ResourceKeyspace = resourceKeyspace + + FindKeyspaceByName = findKeyspaceByName +) diff --git a/internal/service/keyspaces/find.go b/internal/service/keyspaces/find.go index c22dcee84eae..5929693f2676 100644 --- a/internal/service/keyspaces/find.go +++ b/internal/service/keyspaces/find.go @@ -10,31 +10,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -func FindKeyspaceByName(ctx context.Context, conn *keyspaces.Keyspaces, name string) (*keyspaces.GetKeyspaceOutput, error) { - input := keyspaces.GetKeyspaceInput{ - KeyspaceName: aws.String(name), - } - - output, err := conn.GetKeyspaceWithContext(ctx, &input) - - if tfawserr.ErrCodeEquals(err, keyspaces.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err - } - - if output == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - return output, nil -} - func FindTableByTwoPartKey(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string) (*keyspaces.GetTableOutput, error) { input := keyspaces.GetTableInput{ KeyspaceName: aws.String(keyspaceName), diff --git a/internal/service/keyspaces/keyspace.go b/internal/service/keyspaces/keyspace.go index 5391de6b2b49..5e9c4b899480 100644 --- a/internal/service/keyspaces/keyspace.go +++ b/internal/service/keyspaces/keyspace.go @@ -6,13 +6,15 @@ import ( "regexp" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" - "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/keyspaces" + "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" 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" @@ -21,7 +23,7 @@ import ( // @SDKResource("aws_keyspaces_keyspace", name="Keyspace") // @Tags(identifierAttribute="arn") -func ResourceKeyspace() *schema.Resource { +func resourceKeyspace() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceKeyspaceCreate, ReadWithoutTimeout: resourceKeyspaceRead, @@ -60,7 +62,7 @@ func ResourceKeyspace() *schema.Resource { } func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) name := d.Get("name").(string) input := &keyspaces.CreateKeyspaceInput{ @@ -68,7 +70,7 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in Tags: getTagsIn(ctx), } - _, err := conn.CreateKeyspaceWithContext(ctx, input) + _, err := conn.CreateKeyspace(ctx, input) if err != nil { return diag.Errorf("creating Keyspaces Keyspace (%s): %s", name, err) @@ -77,7 +79,7 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in d.SetId(name) _, err = tfresource.RetryWhenNotFound(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { - return FindKeyspaceByName(ctx, conn, d.Id()) + return findKeyspaceByName(ctx, conn, d.Id()) }) if err != nil { @@ -88,9 +90,9 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in } func resourceKeyspaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) - keyspace, err := FindKeyspaceByName(ctx, conn, d.Id()) + keyspace, err := findKeyspaceByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Keyspaces Keyspace (%s) not found, removing from state", d.Id()) @@ -114,18 +116,18 @@ func resourceKeyspaceUpdate(ctx context.Context, d *schema.ResourceData, meta in } func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) log.Printf("[DEBUG] Deleting Keyspaces Keyspace: (%s)", d.Id()) - _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, d.Timeout(schema.TimeoutDelete), + _, err := tfresource.RetryWhenIsAErrorMessageContains[*types.ConflictException](ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { - return conn.DeleteKeyspaceWithContext(ctx, &keyspaces.DeleteKeyspaceInput{ + return conn.DeleteKeyspace(ctx, &keyspaces.DeleteKeyspaceInput{ KeyspaceName: aws.String(d.Id()), }) }, - keyspaces.ErrCodeConflictException, "a table under it is currently being created or deleted") + "a table under it is currently being created or deleted") - if tfawserr.ErrCodeEquals(err, keyspaces.ErrCodeResourceNotFoundException) { + if errs.IsA[*types.ResourceNotFoundException](err) { return nil } @@ -134,7 +136,7 @@ func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta in } _, err = tfresource.RetryUntilNotFound(ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { - return FindKeyspaceByName(ctx, conn, d.Id()) + return findKeyspaceByName(ctx, conn, d.Id()) }) if err != nil { @@ -143,3 +145,28 @@ func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta in return nil } + +func findKeyspaceByName(ctx context.Context, conn *keyspaces.Client, name string) (*keyspaces.GetKeyspaceOutput, error) { + input := keyspaces.GetKeyspaceInput{ + KeyspaceName: aws.String(name), + } + + output, err := conn.GetKeyspace(ctx, &input) + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output, nil +} diff --git a/internal/service/keyspaces/service_package_gen.go b/internal/service/keyspaces/service_package_gen.go index 076826d26924..726817456b6f 100644 --- a/internal/service/keyspaces/service_package_gen.go +++ b/internal/service/keyspaces/service_package_gen.go @@ -29,7 +29,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceKeyspace, + Factory: resourceKeyspace, TypeName: "aws_keyspaces_keyspace", Name: "Keyspace", Tags: &types.ServicePackageResourceTags{ From 83b5d361ff1bce75af52b00bfc413ec38d06a744 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:49:54 -0400 Subject: [PATCH 09/13] r/aws_keyspaces_table: Migrate to AWS SDK for Go v2. --- internal/service/keyspaces/exports_test.go | 4 +- internal/service/keyspaces/find.go | 44 --- .../service/keyspaces/service_package_gen.go | 2 +- internal/service/keyspaces/table.go | 321 +++++++++--------- 4 files changed, 166 insertions(+), 205 deletions(-) delete mode 100644 internal/service/keyspaces/find.go diff --git a/internal/service/keyspaces/exports_test.go b/internal/service/keyspaces/exports_test.go index 649cdf379d14..7d9f4fe2a3c4 100644 --- a/internal/service/keyspaces/exports_test.go +++ b/internal/service/keyspaces/exports_test.go @@ -3,6 +3,8 @@ package keyspaces // Exports for use in tests only. var ( ResourceKeyspace = resourceKeyspace + ResourceTable = resourceTable - FindKeyspaceByName = findKeyspaceByName + FindKeyspaceByName = findKeyspaceByName + FindTableByTwoPartKey = findTableByTwoPartKey ) diff --git a/internal/service/keyspaces/find.go b/internal/service/keyspaces/find.go deleted file mode 100644 index 5929693f2676..000000000000 --- a/internal/service/keyspaces/find.go +++ /dev/null @@ -1,44 +0,0 @@ -package keyspaces - -import ( - "context" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" -) - -func FindTableByTwoPartKey(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string) (*keyspaces.GetTableOutput, error) { - input := keyspaces.GetTableInput{ - KeyspaceName: aws.String(keyspaceName), - TableName: aws.String(tableName), - } - - output, err := conn.GetTableWithContext(ctx, &input) - - if tfawserr.ErrCodeEquals(err, keyspaces.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err - } - - if output == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - if status := aws.StringValue(output.Status); status == keyspaces.TableStatusDeleted { - return nil, &retry.NotFoundError{ - Message: status, - LastRequest: input, - } - } - - return output, nil -} diff --git a/internal/service/keyspaces/service_package_gen.go b/internal/service/keyspaces/service_package_gen.go index 726817456b6f..0cd9bb3325d8 100644 --- a/internal/service/keyspaces/service_package_gen.go +++ b/internal/service/keyspaces/service_package_gen.go @@ -37,7 +37,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka }, }, { - Factory: ResourceTable, + Factory: resourceTable, TypeName: "aws_keyspaces_table", Name: "Table", Tags: &types.ServicePackageResourceTags{ diff --git a/internal/service/keyspaces/table.go b/internal/service/keyspaces/table.go index 0e72e08f0662..052e358c9b68 100644 --- a/internal/service/keyspaces/table.go +++ b/internal/service/keyspaces/table.go @@ -8,15 +8,17 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" - "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/keyspaces" + "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "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" 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" @@ -25,7 +27,7 @@ import ( // @SDKResource("aws_keyspaces_table", name="Table") // @Tags(identifierAttribute="arn") -func ResourceTable() *schema.Resource { +func resourceTable() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceTableCreate, ReadWithoutTimeout: resourceTableRead, @@ -76,10 +78,10 @@ func ResourceTable() *schema.Resource { ValidateFunc: validation.IntAtLeast(1), }, "throughput_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(keyspaces.ThroughputMode_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[types.ThroughputMode](), }, "write_capacity_units": { Type: schema.TypeInt, @@ -124,10 +126,10 @@ func ResourceTable() *schema.Resource { ValidateFunc: verify.ValidARN, }, "type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(keyspaces.EncryptionType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[types.EncryptionType](), }, }, }, @@ -149,10 +151,10 @@ func ResourceTable() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "status": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(keyspaces.PointInTimeRecoveryStatus_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[types.PointInTimeRecoveryStatus](), }, }, }, @@ -179,10 +181,10 @@ func ResourceTable() *schema.Resource { ), }, "order_by": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(keyspaces.SortOrder_Values(), false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[types.SortOrder](), }, }, }, @@ -268,9 +270,9 @@ func ResourceTable() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "status": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(keyspaces.TimeToLiveStatus_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[types.TimeToLiveStatus](), }, }, }, @@ -280,7 +282,7 @@ func ResourceTable() *schema.Resource { } func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) keyspaceName := d.Get("keyspace_name").(string) tableName := d.Get("table_name").(string) @@ -300,7 +302,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter } if v, ok := d.GetOk("default_time_to_live"); ok { - input.DefaultTimeToLive = aws.Int64(int64(v.(int))) + input.DefaultTimeToLive = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("encryption_specification"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -319,7 +321,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter input.Ttl = expandTimeToLive(v.([]interface{})[0].(map[string]interface{})) } - _, err := conn.CreateTableWithContext(ctx, input) + _, err := conn.CreateTable(ctx, input) if err != nil { return diag.Errorf("creating Keyspaces Table (%s): %s", id, err) @@ -335,7 +337,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter } func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) keyspaceName, tableName, err := TableParseResourceID(d.Id()) @@ -343,7 +345,7 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa return diag.FromErr(err) } - table, err := FindTableByTwoPartKey(ctx, conn, keyspaceName, tableName) + table, err := findTableByTwoPartKey(ctx, conn, keyspaceName, tableName) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] Keyspaces Table (%s) not found, removing from state", d.Id()) @@ -406,7 +408,7 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa } func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) keyspaceName, tableName, err := TableParseResourceID(d.Id()) @@ -425,8 +427,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter TableName: aws.String(tableName), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) CapacitySpecification: %s", d.Id(), err) @@ -440,13 +441,12 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter if d.HasChange("default_time_to_live") { input := &keyspaces.UpdateTableInput{ - DefaultTimeToLive: aws.Int64(int64(d.Get("default_time_to_live").(int))), + DefaultTimeToLive: aws.Int32(int32(d.Get("default_time_to_live").(int))), KeyspaceName: aws.String(keyspaceName), TableName: aws.String(tableName), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) DefaultTimeToLive: %s", d.Id(), err) @@ -465,8 +465,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter TableName: aws.String(tableName), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) EncryptionSpecification: %s", d.Id(), err) @@ -486,8 +485,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter TableName: aws.String(tableName), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) PointInTimeRecovery: %s", d.Id(), err) @@ -507,8 +505,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter Ttl: expandTimeToLive(v.([]interface{})[0].(map[string]interface{})), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) Ttl: %s", d.Id(), err) @@ -543,8 +540,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter TableName: aws.String(tableName), } - log.Printf("[DEBUG] Updating Keyspaces Table: %s", input) - _, err := conn.UpdateTableWithContext(ctx, input) + _, err := conn.UpdateTable(ctx, input) if err != nil { return diag.Errorf("updating Keyspaces Table (%s) AddColumns: %s", d.Id(), err) @@ -562,7 +558,7 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter } func resourceTableDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).KeyspacesConn(ctx) + conn := meta.(*conns.AWSClient).KeyspacesClient(ctx) keyspaceName, tableName, err := TableParseResourceID(d.Id()) @@ -571,12 +567,12 @@ func resourceTableDelete(ctx context.Context, d *schema.ResourceData, meta inter } log.Printf("[DEBUG] Deleting Keyspaces Table: (%s)", d.Id()) - _, err = conn.DeleteTableWithContext(ctx, &keyspaces.DeleteTableInput{ + _, err = conn.DeleteTable(ctx, &keyspaces.DeleteTableInput{ KeyspaceName: aws.String(keyspaceName), TableName: aws.String(tableName), }) - if tfawserr.ErrCodeEquals(err, keyspaces.ErrCodeResourceNotFoundException) { + if errs.IsA[*types.ResourceNotFoundException](err) { return nil } @@ -610,9 +606,42 @@ func TableParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected KEYSPACE-NAME%[2]sTABLE-NAME", id, tableIDSeparator) } -func statusTable(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string) retry.StateRefreshFunc { +func findTableByTwoPartKey(ctx context.Context, conn *keyspaces.Client, keyspaceName, tableName string) (*keyspaces.GetTableOutput, error) { + input := keyspaces.GetTableInput{ + KeyspaceName: aws.String(keyspaceName), + TableName: aws.String(tableName), + } + + output, err := conn.GetTable(ctx, &input) + + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + if status := output.Status; status == types.TableStatusDeleted { + return nil, &retry.NotFoundError{ + Message: string(status), + LastRequest: input, + } + } + + return output, nil +} + +func statusTable(ctx context.Context, conn *keyspaces.Client, keyspaceName, tableName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindTableByTwoPartKey(ctx, conn, keyspaceName, tableName) + output, err := findTableByTwoPartKey(ctx, conn, keyspaceName, tableName) if tfresource.NotFound(err) { return nil, "", nil @@ -622,14 +651,14 @@ func statusTable(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, t return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitTableCreated(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { +func waitTableCreated(ctx context.Context, conn *keyspaces.Client, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{keyspaces.TableStatusCreating}, - Target: []string{keyspaces.TableStatusActive}, + Pending: enum.Slice(types.TableStatusCreating), + Target: enum.Slice(types.TableStatusActive), Refresh: statusTable(ctx, conn, keyspaceName, tableName), Timeout: timeout, } @@ -643,9 +672,9 @@ func waitTableCreated(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceNa return nil, err } -func waitTableDeleted(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { +func waitTableDeleted(ctx context.Context, conn *keyspaces.Client, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{keyspaces.TableStatusActive, keyspaces.TableStatusDeleting}, + Pending: enum.Slice(types.TableStatusActive, types.TableStatusDeleting), Target: []string{}, Refresh: statusTable(ctx, conn, keyspaceName, tableName), Timeout: timeout, @@ -660,10 +689,10 @@ func waitTableDeleted(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceNa return nil, err } -func waitTableUpdated(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { //nolint:unparam +func waitTableUpdated(ctx context.Context, conn *keyspaces.Client, keyspaceName, tableName string, timeout time.Duration) (*keyspaces.GetTableOutput, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ - Pending: []string{keyspaces.TableStatusUpdating}, - Target: []string{keyspaces.TableStatusActive}, + Pending: enum.Slice(types.TableStatusUpdating), + Target: enum.Slice(types.TableStatusActive), Refresh: statusTable(ctx, conn, keyspaceName, tableName), Timeout: timeout, Delay: 10 * time.Second, @@ -678,19 +707,19 @@ func waitTableUpdated(ctx context.Context, conn *keyspaces.Keyspaces, keyspaceNa return nil, err } -func expandCapacitySpecification(tfMap map[string]interface{}) *keyspaces.CapacitySpecification { +func expandCapacitySpecification(tfMap map[string]interface{}) *types.CapacitySpecification { if tfMap == nil { return nil } - apiObject := &keyspaces.CapacitySpecification{} + apiObject := &types.CapacitySpecification{} if v, ok := tfMap["read_capacity_units"].(int); ok && v != 0 { apiObject.ReadCapacityUnits = aws.Int64(int64(v)) } if v, ok := tfMap["throughput_mode"].(string); ok && v != "" { - apiObject.ThroughputMode = aws.String(v) + apiObject.ThroughputMode = types.ThroughputMode(v) } if v, ok := tfMap["write_capacity_units"].(int); ok && v != 0 { @@ -700,12 +729,12 @@ func expandCapacitySpecification(tfMap map[string]interface{}) *keyspaces.Capaci return apiObject } -func expandComment(tfMap map[string]interface{}) *keyspaces.Comment { +func expandComment(tfMap map[string]interface{}) *types.Comment { if tfMap == nil { return nil } - apiObject := &keyspaces.Comment{} + apiObject := &types.Comment{} if v, ok := tfMap["message"].(string); ok && v != "" { apiObject.Message = aws.String(v) @@ -714,44 +743,44 @@ func expandComment(tfMap map[string]interface{}) *keyspaces.Comment { return apiObject } -func expandEncryptionSpecification(tfMap map[string]interface{}) *keyspaces.EncryptionSpecification { +func expandEncryptionSpecification(tfMap map[string]interface{}) *types.EncryptionSpecification { if tfMap == nil { return nil } - apiObject := &keyspaces.EncryptionSpecification{} + apiObject := &types.EncryptionSpecification{} if v, ok := tfMap["kms_key_identifier"].(string); ok && v != "" { apiObject.KmsKeyIdentifier = aws.String(v) } if v, ok := tfMap["type"].(string); ok && v != "" { - apiObject.Type = aws.String(v) + apiObject.Type = types.EncryptionType(v) } return apiObject } -func expandPointInTimeRecovery(tfMap map[string]interface{}) *keyspaces.PointInTimeRecovery { +func expandPointInTimeRecovery(tfMap map[string]interface{}) *types.PointInTimeRecovery { if tfMap == nil { return nil } - apiObject := &keyspaces.PointInTimeRecovery{} + apiObject := &types.PointInTimeRecovery{} if v, ok := tfMap["status"].(string); ok && v != "" { - apiObject.Status = aws.String(v) + apiObject.Status = types.PointInTimeRecoveryStatus(v) } return apiObject } -func expandSchemaDefinition(tfMap map[string]interface{}) *keyspaces.SchemaDefinition { +func expandSchemaDefinition(tfMap map[string]interface{}) *types.SchemaDefinition { if tfMap == nil { return nil } - apiObject := &keyspaces.SchemaDefinition{} + apiObject := &types.SchemaDefinition{} if v, ok := tfMap["clustering_key"].([]interface{}); ok && len(v) > 0 { apiObject.ClusteringKeys = expandClusteringKeys(v) @@ -772,26 +801,26 @@ func expandSchemaDefinition(tfMap map[string]interface{}) *keyspaces.SchemaDefin return apiObject } -func expandTimeToLive(tfMap map[string]interface{}) *keyspaces.TimeToLive { +func expandTimeToLive(tfMap map[string]interface{}) *types.TimeToLive { if tfMap == nil { return nil } - apiObject := &keyspaces.TimeToLive{} + apiObject := &types.TimeToLive{} if v, ok := tfMap["status"].(string); ok && v != "" { - apiObject.Status = aws.String(v) + apiObject.Status = types.TimeToLiveStatus(v) } return apiObject } -func expandColumnDefinition(tfMap map[string]interface{}) *keyspaces.ColumnDefinition { +func expandColumnDefinition(tfMap map[string]interface{}) *types.ColumnDefinition { if tfMap == nil { return nil } - apiObject := &keyspaces.ColumnDefinition{} + apiObject := &types.ColumnDefinition{} if v, ok := tfMap["name"].(string); ok && v != "" { apiObject.Name = aws.String(v) @@ -804,12 +833,12 @@ func expandColumnDefinition(tfMap map[string]interface{}) *keyspaces.ColumnDefin return apiObject } -func expandColumnDefinitions(tfList []interface{}) []*keyspaces.ColumnDefinition { +func expandColumnDefinitions(tfList []interface{}) []types.ColumnDefinition { if len(tfList) == 0 { return nil } - var apiObjects []*keyspaces.ColumnDefinition + var apiObjects []types.ColumnDefinition for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -824,36 +853,36 @@ func expandColumnDefinitions(tfList []interface{}) []*keyspaces.ColumnDefinition continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func expandClusteringKey(tfMap map[string]interface{}) *keyspaces.ClusteringKey { +func expandClusteringKey(tfMap map[string]interface{}) *types.ClusteringKey { if tfMap == nil { return nil } - apiObject := &keyspaces.ClusteringKey{} + apiObject := &types.ClusteringKey{} if v, ok := tfMap["name"].(string); ok && v != "" { apiObject.Name = aws.String(v) } if v, ok := tfMap["order_by"].(string); ok && v != "" { - apiObject.OrderBy = aws.String(v) + apiObject.OrderBy = types.SortOrder(v) } return apiObject } -func expandClusteringKeys(tfList []interface{}) []*keyspaces.ClusteringKey { +func expandClusteringKeys(tfList []interface{}) []types.ClusteringKey { if len(tfList) == 0 { return nil } - var apiObjects []*keyspaces.ClusteringKey + var apiObjects []types.ClusteringKey for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -868,18 +897,18 @@ func expandClusteringKeys(tfList []interface{}) []*keyspaces.ClusteringKey { continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func expandPartitionKey(tfMap map[string]interface{}) *keyspaces.PartitionKey { +func expandPartitionKey(tfMap map[string]interface{}) *types.PartitionKey { if tfMap == nil { return nil } - apiObject := &keyspaces.PartitionKey{} + apiObject := &types.PartitionKey{} if v, ok := tfMap["name"].(string); ok && v != "" { apiObject.Name = aws.String(v) @@ -888,12 +917,12 @@ func expandPartitionKey(tfMap map[string]interface{}) *keyspaces.PartitionKey { return apiObject } -func expandPartitionKeys(tfList []interface{}) []*keyspaces.PartitionKey { +func expandPartitionKeys(tfList []interface{}) []types.PartitionKey { if len(tfList) == 0 { return nil } - var apiObjects []*keyspaces.PartitionKey + var apiObjects []types.PartitionKey for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -908,18 +937,18 @@ func expandPartitionKeys(tfList []interface{}) []*keyspaces.PartitionKey { continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func expandStaticColumn(tfMap map[string]interface{}) *keyspaces.StaticColumn { +func expandStaticColumn(tfMap map[string]interface{}) *types.StaticColumn { if tfMap == nil { return nil } - apiObject := &keyspaces.StaticColumn{} + apiObject := &types.StaticColumn{} if v, ok := tfMap["name"].(string); ok && v != "" { apiObject.Name = aws.String(v) @@ -928,12 +957,12 @@ func expandStaticColumn(tfMap map[string]interface{}) *keyspaces.StaticColumn { return apiObject } -func expandStaticColumns(tfList []interface{}) []*keyspaces.StaticColumn { +func expandStaticColumns(tfList []interface{}) []types.StaticColumn { if len(tfList) == 0 { return nil } - var apiObjects []*keyspaces.StaticColumn + var apiObjects []types.StaticColumn for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -948,35 +977,33 @@ func expandStaticColumns(tfList []interface{}) []*keyspaces.StaticColumn { continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func flattenCapacitySpecificationSummary(apiObject *keyspaces.CapacitySpecificationSummary) map[string]interface{} { +func flattenCapacitySpecificationSummary(apiObject *types.CapacitySpecificationSummary) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.ReadCapacityUnits; v != nil { - tfMap["read_capacity_units"] = aws.Int64Value(v) + tfMap := map[string]interface{}{ + "throughput_mode": apiObject.ThroughputMode, } - if v := apiObject.ThroughputMode; v != nil { - tfMap["throughput_mode"] = aws.StringValue(v) + if v := apiObject.ReadCapacityUnits; v != nil { + tfMap["read_capacity_units"] = aws.ToInt64(v) } if v := apiObject.WriteCapacityUnits; v != nil { - tfMap["write_capacity_units"] = aws.Int64Value(v) + tfMap["write_capacity_units"] = aws.ToInt64(v) } return tfMap } -func flattenComment(apiObject *keyspaces.Comment) map[string]interface{} { +func flattenComment(apiObject *types.Comment) map[string]interface{} { if apiObject == nil { return nil } @@ -984,45 +1011,41 @@ func flattenComment(apiObject *keyspaces.Comment) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.Message; v != nil { - tfMap["message"] = aws.StringValue(v) + tfMap["message"] = aws.ToString(v) } return tfMap } -func flattenEncryptionSpecification(apiObject *keyspaces.EncryptionSpecification) map[string]interface{} { +func flattenEncryptionSpecification(apiObject *types.EncryptionSpecification) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.KmsKeyIdentifier; v != nil { - tfMap["kms_key_identifier"] = aws.StringValue(v) + tfMap := map[string]interface{}{ + "types": apiObject.Type, } - if v := apiObject.Type; v != nil { - tfMap["type"] = aws.StringValue(v) + if v := apiObject.KmsKeyIdentifier; v != nil { + tfMap["kms_key_identifier"] = aws.ToString(v) } return tfMap } -func flattenPointInTimeRecoverySummary(apiObject *keyspaces.PointInTimeRecoverySummary) map[string]interface{} { +func flattenPointInTimeRecoverySummary(apiObject *types.PointInTimeRecoverySummary) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.Status; v != nil { - tfMap["status"] = aws.StringValue(v) + tfMap := map[string]interface{}{ + "status": apiObject.Status, } return tfMap } -func flattenSchemaDefinition(apiObject *keyspaces.SchemaDefinition) map[string]interface{} { +func flattenSchemaDefinition(apiObject *types.SchemaDefinition) map[string]interface{} { if apiObject == nil { return nil } @@ -1048,21 +1071,19 @@ func flattenSchemaDefinition(apiObject *keyspaces.SchemaDefinition) map[string]i return tfMap } -func flattenTimeToLive(apiObject *keyspaces.TimeToLive) map[string]interface{} { +func flattenTimeToLive(apiObject *types.TimeToLive) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.Status; v != nil { - tfMap["status"] = aws.StringValue(v) + tfMap := map[string]interface{}{ + "status": apiObject.Status, } return tfMap } -func flattenColumnDefinition(apiObject *keyspaces.ColumnDefinition) map[string]interface{} { +func flattenColumnDefinition(apiObject *types.ColumnDefinition) map[string]interface{} { if apiObject == nil { return nil } @@ -1070,17 +1091,17 @@ func flattenColumnDefinition(apiObject *keyspaces.ColumnDefinition) map[string]i tfMap := map[string]interface{}{} if v := apiObject.Name; v != nil { - tfMap["name"] = aws.StringValue(v) + tfMap["name"] = aws.ToString(v) } if v := apiObject.Type; v != nil { - tfMap["type"] = aws.StringValue(v) + tfMap["type"] = aws.ToString(v) } return tfMap } -func flattenColumnDefinitions(apiObjects []*keyspaces.ColumnDefinition) []interface{} { +func flattenColumnDefinitions(apiObjects []types.ColumnDefinition) []interface{} { if len(apiObjects) == 0 { return nil } @@ -1088,35 +1109,29 @@ func flattenColumnDefinitions(apiObjects []*keyspaces.ColumnDefinition) []interf var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenColumnDefinition(apiObject)) + tfList = append(tfList, flattenColumnDefinition(&apiObject)) } return tfList } -func flattenClusteringKey(apiObject *keyspaces.ClusteringKey) map[string]interface{} { +func flattenClusteringKey(apiObject *types.ClusteringKey) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.Name; v != nil { - tfMap["name"] = aws.StringValue(v) + tfMap := map[string]interface{}{ + "order_by": apiObject.OrderBy, } - if v := apiObject.OrderBy; v != nil { - tfMap["order_by"] = aws.StringValue(v) + if v := apiObject.Name; v != nil { + tfMap["name"] = aws.ToString(v) } return tfMap } -func flattenClusteringKeys(apiObjects []*keyspaces.ClusteringKey) []interface{} { +func flattenClusteringKeys(apiObjects []types.ClusteringKey) []interface{} { if len(apiObjects) == 0 { return nil } @@ -1124,17 +1139,13 @@ func flattenClusteringKeys(apiObjects []*keyspaces.ClusteringKey) []interface{} var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenClusteringKey(apiObject)) + tfList = append(tfList, flattenClusteringKey(&apiObject)) } return tfList } -func flattenPartitionKey(apiObject *keyspaces.PartitionKey) map[string]interface{} { +func flattenPartitionKey(apiObject *types.PartitionKey) map[string]interface{} { if apiObject == nil { return nil } @@ -1142,13 +1153,13 @@ func flattenPartitionKey(apiObject *keyspaces.PartitionKey) map[string]interface tfMap := map[string]interface{}{} if v := apiObject.Name; v != nil { - tfMap["name"] = aws.StringValue(v) + tfMap["name"] = aws.ToString(v) } return tfMap } -func flattenPartitionKeys(apiObjects []*keyspaces.PartitionKey) []interface{} { +func flattenPartitionKeys(apiObjects []types.PartitionKey) []interface{} { if len(apiObjects) == 0 { return nil } @@ -1156,17 +1167,13 @@ func flattenPartitionKeys(apiObjects []*keyspaces.PartitionKey) []interface{} { var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenPartitionKey(apiObject)) + tfList = append(tfList, flattenPartitionKey(&apiObject)) } return tfList } -func flattenStaticColumn(apiObject *keyspaces.StaticColumn) map[string]interface{} { +func flattenStaticColumn(apiObject *types.StaticColumn) map[string]interface{} { if apiObject == nil { return nil } @@ -1174,13 +1181,13 @@ func flattenStaticColumn(apiObject *keyspaces.StaticColumn) map[string]interface tfMap := map[string]interface{}{} if v := apiObject.Name; v != nil { - tfMap["name"] = aws.StringValue(v) + tfMap["name"] = aws.ToString(v) } return tfMap } -func flattenStaticColumns(apiObjects []*keyspaces.StaticColumn) []interface{} { +func flattenStaticColumns(apiObjects []types.StaticColumn) []interface{} { if len(apiObjects) == 0 { return nil } @@ -1188,11 +1195,7 @@ func flattenStaticColumns(apiObjects []*keyspaces.StaticColumn) []interface{} { var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - - tfList = append(tfList, flattenStaticColumn(apiObject)) + tfList = append(tfList, flattenStaticColumn(&apiObject)) } return tfList From 6dd4a601987d93fac3d436684e274de4e98eeaaf Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 2 Jul 2023 16:54:27 -0400 Subject: [PATCH 10/13] keyspaces: Migrate acceptance tests to AWS SDK for Go v2. --- internal/service/keyspaces/keyspace_test.go | 12 ++++----- internal/service/keyspaces/table.go | 2 +- internal/service/keyspaces/table_test.go | 27 +++++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal/service/keyspaces/keyspace_test.go b/internal/service/keyspaces/keyspace_test.go index 24130306b63c..baf2db08483c 100644 --- a/internal/service/keyspaces/keyspace_test.go +++ b/internal/service/keyspaces/keyspace_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/keyspaces" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -14,6 +13,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfkeyspaces "github.com/hashicorp/terraform-provider-aws/internal/service/keyspaces" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func testAccPreCheck(t *testing.T) { @@ -27,7 +27,7 @@ func TestAccKeyspacesKeyspace_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckKeyspaceDestroy(ctx), Steps: []resource.TestStep{ @@ -56,7 +56,7 @@ func TestAccKeyspacesKeyspace_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckKeyspaceDestroy(ctx), Steps: []resource.TestStep{ @@ -79,7 +79,7 @@ func TestAccKeyspacesKeyspace_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckKeyspaceDestroy(ctx), Steps: []resource.TestStep{ @@ -119,7 +119,7 @@ func TestAccKeyspacesKeyspace_tags(t *testing.T) { func testAccCheckKeyspaceDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_keyspaces_keyspace" { @@ -154,7 +154,7 @@ func testAccCheckKeyspaceExists(ctx context.Context, n string) resource.TestChec return fmt.Errorf("No Keyspaces Keyspace ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesClient(ctx) _, err := tfkeyspaces.FindKeyspaceByName(ctx, conn, rs.Primary.Attributes["name"]) diff --git a/internal/service/keyspaces/table.go b/internal/service/keyspaces/table.go index 052e358c9b68..cda64fc1d1d7 100644 --- a/internal/service/keyspaces/table.go +++ b/internal/service/keyspaces/table.go @@ -1023,7 +1023,7 @@ func flattenEncryptionSpecification(apiObject *types.EncryptionSpecification) ma } tfMap := map[string]interface{}{ - "types": apiObject.Type, + "type": apiObject.Type, } if v := apiObject.KmsKeyIdentifier; v != nil { diff --git a/internal/service/keyspaces/table_test.go b/internal/service/keyspaces/table_test.go index 7034e9192241..3e0d0ab7ff4b 100644 --- a/internal/service/keyspaces/table_test.go +++ b/internal/service/keyspaces/table_test.go @@ -6,8 +6,8 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/keyspaces" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfkeyspaces "github.com/hashicorp/terraform-provider-aws/internal/service/keyspaces" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccKeyspacesTable_basic(t *testing.T) { @@ -26,7 +27,7 @@ func TestAccKeyspacesTable_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -80,7 +81,7 @@ func TestAccKeyspacesTable_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -105,7 +106,7 @@ func TestAccKeyspacesTable_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -152,7 +153,7 @@ func TestAccKeyspacesTable_multipleColumns(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -247,7 +248,7 @@ func TestAccKeyspacesTable_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -320,7 +321,7 @@ func TestAccKeyspacesTable_addColumns(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -387,7 +388,7 @@ func TestAccKeyspacesTable_delColumns(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, keyspaces.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckTableDestroy(ctx), Steps: []resource.TestStep{ @@ -447,7 +448,7 @@ func TestAccKeyspacesTable_delColumns(t *testing.T) { func testAccCheckTableDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_keyspaces_table" { @@ -488,7 +489,7 @@ func testAccCheckTableExists(ctx context.Context, n string, v *keyspaces.GetTabl return fmt.Errorf("No Keyspaces Table ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).KeyspacesClient(ctx) keyspaceName, tableName, err := tfkeyspaces.TableParseResourceID(rs.Primary.ID) @@ -510,7 +511,7 @@ func testAccCheckTableExists(ctx context.Context, n string, v *keyspaces.GetTabl func testAccCheckTableNotRecreated(i, j *keyspaces.GetTableOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if !aws.TimeValue(i.CreationTimestamp).Equal(aws.TimeValue(j.CreationTimestamp)) { + if !aws.ToTime(i.CreationTimestamp).Equal(aws.ToTime(j.CreationTimestamp)) { return errors.New("Keyspaces Table was recreated") } @@ -520,7 +521,7 @@ func testAccCheckTableNotRecreated(i, j *keyspaces.GetTableOutput) resource.Test func testAccCheckTableRecreated(i, j *keyspaces.GetTableOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.TimeValue(i.CreationTimestamp).Equal(aws.TimeValue(j.CreationTimestamp)) { + if aws.ToTime(i.CreationTimestamp).Equal(aws.ToTime(j.CreationTimestamp)) { return errors.New("Keyspaces Table was not recreated") } From 91714b38d94ad70897da1acbb086d5e390570bc4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 3 Jul 2023 08:25:41 -0400 Subject: [PATCH 11/13] keyspaces: Migrate sweepers to AWS SDK for Go v2. --- internal/service/keyspaces/sweep.go | 35 +++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/internal/service/keyspaces/sweep.go b/internal/service/keyspaces/sweep.go index 67ddcfdd009e..9e73102901f7 100644 --- a/internal/service/keyspaces/sweep.go +++ b/internal/service/keyspaces/sweep.go @@ -7,8 +7,8 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/keyspaces" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/keyspaces" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" ) @@ -27,17 +27,25 @@ func sweepKeyspaces(region string) error { // nosemgrep:ci.keyspaces-in-func-nam if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.KeyspacesConn(ctx) + conn := client.KeyspacesClient(ctx) input := &keyspaces.ListKeyspacesInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.ListKeyspacesPagesWithContext(ctx, input, func(page *keyspaces.ListKeyspacesOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := keyspaces.NewListKeyspacesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if sweep.SkipSweepError(err) { + log.Printf("[WARN] Skipping Keyspaces Keyspace sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing Keyspaces Keyspaces (%s): %w", region, err) } for _, v := range page.Keyspaces { - id := aws.StringValue(v.KeyspaceName) + id := aws.ToString(v.KeyspaceName) switch id { case "system_schema", "system_schema_mcs", "system", "system_multiregion_info": @@ -45,23 +53,12 @@ func sweepKeyspaces(region string) error { // nosemgrep:ci.keyspaces-in-func-nam continue } - r := ResourceKeyspace() + r := resourceKeyspace() d := r.Data(nil) d.SetId(id) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping Keyspaces Keyspace sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing Keyspaces Keyspaces (%s): %w", region, err) } err = sweep.SweepOrchestratorWithContext(ctx, sweepResources) From ce0b979dc00a3da88e0922d302293d0cd7e990a7 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 3 Jul 2023 08:26:24 -0400 Subject: [PATCH 12/13] r/aws_aws_keyspaces_table: Add 'client_side_timestamps' configuration block. --- .changelog/#####.txt | 3 + internal/service/keyspaces/table.go | 81 +++++++++++++++++++- internal/service/keyspaces/table_test.go | 59 ++++++++++++++ website/docs/r/keyspaces_table.html.markdown | 5 ++ 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 000000000000..9d90109ec772 --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_aws_keyspaces_table: Add `client_side_timestamps` configuration block +``` \ No newline at end of file diff --git a/internal/service/keyspaces/table.go b/internal/service/keyspaces/table.go index cda64fc1d1d7..c6b1421218cd 100644 --- a/internal/service/keyspaces/table.go +++ b/internal/service/keyspaces/table.go @@ -45,10 +45,14 @@ func resourceTable() *schema.Resource { }, CustomizeDiff: customdiff.Sequence( - customdiff.ForceNewIfChange("schema_definition.0.column", func(_ context.Context, o, n, meta interface{}) bool { + customdiff.ForceNewIfChange("client_side_timestamps", func(_ context.Context, old, new, meta interface{}) bool { + // Client-side timestamps cannot be disabled. + return len(old.([]interface{})) == 1 && len(new.([]interface{})) == 0 + }), + customdiff.ForceNewIfChange("schema_definition.0.column", func(_ context.Context, old, new, meta interface{}) bool { // Columns can only be added. - if os, ok := o.(*schema.Set); ok { - if ns, ok := n.(*schema.Set); ok { + if os, ok := old.(*schema.Set); ok { + if ns, ok := new.(*schema.Set); ok { if del := os.Difference(ns); del.Len() > 0 { return true } @@ -91,6 +95,20 @@ func resourceTable() *schema.Resource { }, }, }, + "client_side_timestamps": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "status": { + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[types.ClientSideTimestampsStatus](), + }, + }, + }, + }, "comment": { Type: schema.TypeList, Optional: true, @@ -297,6 +315,10 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter input.CapacitySpecification = expandCapacitySpecification(v.([]interface{})[0].(map[string]interface{})) } + if v, ok := d.GetOk("client_side_timestamps"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input.ClientSideTimestamps = expandClientSideTimestamps(v.([]interface{})[0].(map[string]interface{})) + } + if v, ok := d.GetOk("comment"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.Comment = expandComment(v.([]interface{})[0].(map[string]interface{})) } @@ -365,6 +387,13 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa } else { d.Set("capacity_specification", nil) } + if table.ClientSideTimestamps != nil { + if err := d.Set("client_side_timestamps", []interface{}{flattenClientSideTimestamps(table.ClientSideTimestamps)}); err != nil { + return diag.Errorf("setting client_side_timestamps: %s", err) + } + } else { + d.Set("client_side_timestamps", nil) + } if table.Comment != nil { if err := d.Set("comment", []interface{}{flattenComment(table.Comment)}); err != nil { return diag.Errorf("setting comment: %s", err) @@ -439,6 +468,26 @@ func resourceTableUpdate(ctx context.Context, d *schema.ResourceData, meta inter } } + if d.HasChange("client_side_timestamps") { + if v, ok := d.GetOk("client_side_timestamps"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + input := &keyspaces.UpdateTableInput{ + ClientSideTimestamps: expandClientSideTimestamps(v.([]interface{})[0].(map[string]interface{})), + KeyspaceName: aws.String(keyspaceName), + TableName: aws.String(tableName), + } + + _, err := conn.UpdateTable(ctx, input) + + if err != nil { + return diag.Errorf("updating Keyspaces Table (%s) ClientSideTimestamps: %s", d.Id(), err) + } + + if _, err := waitTableUpdated(ctx, conn, keyspaceName, tableName, d.Timeout(schema.TimeoutUpdate)); err != nil { + return diag.Errorf("waiting for Keyspaces Table (%s) ClientSideTimestamps update: %s", d.Id(), err) + } + } + } + if d.HasChange("default_time_to_live") { input := &keyspaces.UpdateTableInput{ DefaultTimeToLive: aws.Int32(int32(d.Get("default_time_to_live").(int))), @@ -729,6 +778,20 @@ func expandCapacitySpecification(tfMap map[string]interface{}) *types.CapacitySp return apiObject } +func expandClientSideTimestamps(tfMap map[string]interface{}) *types.ClientSideTimestamps { + if tfMap == nil { + return nil + } + + apiObject := &types.ClientSideTimestamps{} + + if v, ok := tfMap["status"].(string); ok && v != "" { + apiObject.Status = types.ClientSideTimestampsStatus(v) + } + + return apiObject +} + func expandComment(tfMap map[string]interface{}) *types.Comment { if tfMap == nil { return nil @@ -1003,6 +1066,18 @@ func flattenCapacitySpecificationSummary(apiObject *types.CapacitySpecificationS return tfMap } +func flattenClientSideTimestamps(apiObject *types.ClientSideTimestamps) map[string]interface{} { + if apiObject == nil { + return nil + } + + tfMap := map[string]interface{}{ + "status": apiObject.Status, + } + + return tfMap +} + func flattenComment(apiObject *types.Comment) map[string]interface{} { if apiObject == nil { return nil diff --git a/internal/service/keyspaces/table_test.go b/internal/service/keyspaces/table_test.go index 3e0d0ab7ff4b..6719ec944218 100644 --- a/internal/service/keyspaces/table_test.go +++ b/internal/service/keyspaces/table_test.go @@ -38,6 +38,7 @@ func TestAccKeyspacesTable_basic(t *testing.T) { acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "cassandra", fmt.Sprintf("/keyspace/%s/table/%s", rName1, rName2)), resource.TestCheckResourceAttr(resourceName, "capacity_specification.#", "1"), resource.TestCheckResourceAttr(resourceName, "capacity_specification.0.throughput_mode", "PAY_PER_REQUEST"), + resource.TestCheckResourceAttr(resourceName, "client_side_timestamps.#", "0"), resource.TestCheckResourceAttr(resourceName, "comment.#", "1"), resource.TestCheckResourceAttr(resourceName, "comment.0.message", ""), resource.TestCheckResourceAttr(resourceName, "default_time_to_live", "0"), @@ -144,6 +145,36 @@ func TestAccKeyspacesTable_tags(t *testing.T) { }) } +func TestAccKeyspacesTable_clientSideTimestamps(t *testing.T) { + ctx := acctest.Context(t) + var v keyspaces.GetTableOutput + rName1 := "tf_acc_test_" + sdkacctest.RandString(20) + rName2 := "tf_acc_test_" + sdkacctest.RandString(20) + resourceName := "aws_keyspaces_table.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, names.KeyspacesEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckTableDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccTableConfig_clientSideTimestamps(rName1, rName2), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckTableExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "client_side_timestamps.#", "1"), + resource.TestCheckResourceAttr(resourceName, "client_side_timestamps.0.status", "ENABLED"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccKeyspacesTable_multipleColumns(t *testing.T) { ctx := acctest.Context(t) var v keyspaces.GetTableOutput @@ -610,6 +641,34 @@ resource "aws_keyspaces_table" "test" { `, rName1, rName2, tagKey1, tagValue1, tagKey2, tagValue2) } +func testAccTableConfig_clientSideTimestamps(rName1, rName2 string) string { + return fmt.Sprintf(` +resource "aws_keyspaces_keyspace" "test" { + name = %[1]q +} + +resource "aws_keyspaces_table" "test" { + keyspace_name = aws_keyspaces_keyspace.test.name + table_name = %[2]q + + schema_definition { + column { + name = "message" + type = "ascii" + } + + partition_key { + name = "message" + } + } + + client_side_timestamps { + status = "ENABLED" + } +} +`, rName1, rName2) +} + func testAccTableConfig_multipleColumns(rName1, rName2 string) string { return fmt.Sprintf(` resource "aws_keyspaces_keyspace" "test" { diff --git a/website/docs/r/keyspaces_table.html.markdown b/website/docs/r/keyspaces_table.html.markdown index 0fa5b97e1fda..194361a8b6b0 100644 --- a/website/docs/r/keyspaces_table.html.markdown +++ b/website/docs/r/keyspaces_table.html.markdown @@ -42,6 +42,7 @@ The following arguments are required: The following arguments are optional: * `capacity_specification` - (Optional) Specifies the read/write throughput capacity mode for the table. +* `client_side_timestamps` - (Optional) Enables client-side timestamps for the table. By default, the setting is disabled. * `comment` - (Optional) A description of the table. * `default_time_to_live` - (Optional) The default Time to Live setting in seconds for the table. More information can be found in the [Developer Guide](https://docs.aws.amazon.com/keyspaces/latest/devguide/TTL-how-it-works.html#ttl-howitworks_default_ttl). * `encryption_specification` - (Optional) Specifies how the encryption key for encryption at rest is managed for the table. More information can be found in the [Developer Guide](https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html). @@ -56,6 +57,10 @@ The `capacity_specification` object takes the following arguments: * `throughput_mode` - (Optional) The read/write throughput capacity mode for a table. Valid values: `PAY_PER_REQUEST`, `PROVISIONED`. The default value is `PAY_PER_REQUEST`. * `write_capacity_units` - (Optional) The throughput capacity specified for write operations defined in write capacity units (WCUs). +The `client_side_timestamps` object takes the following arguments: + +* `status` - (Required) Shows how to enable client-side timestamps settings for the specified table. Valid values: `ENABLED`. + The `comment` object takes the following arguments: * `message` - (Required) A description of the table. From 26239f731b487c1862e7df44c430102c1b079ccb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 3 Jul 2023 08:36:38 -0400 Subject: [PATCH 13/13] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 32339.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 32339.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/32339.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/32339.txt