Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech debt: Migrate keyspaces resources to AWS SDK for Go v2 #32339

Merged
merged 13 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32339.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_aws_keyspaces_table: Add `client_side_timestamps` configuration block
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

10 changes: 10 additions & 0 deletions internal/service/keyspaces/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package keyspaces

// Exports for use in tests only.
var (
ResourceKeyspace = resourceKeyspace
ResourceTable = resourceTable

FindKeyspaceByName = findKeyspaceByName
FindTableByTwoPartKey = findTableByTwoPartKey
)
69 changes: 0 additions & 69 deletions internal/service/keyspaces/find.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/service/keyspaces/generate.go
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
57 changes: 42 additions & 15 deletions internal/service/keyspaces/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -60,15 +62,15 @@ 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{
KeyspaceName: aws.String(name),
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)
Expand All @@ -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 {
Expand All @@ -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())
Expand All @@ -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
}

Expand All @@ -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 {
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions internal/service/keyspaces/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ 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"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"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) {
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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"])

Expand Down
21 changes: 12 additions & 9 deletions internal/service/keyspaces/service_package_gen.go

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

Loading