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

memorydb: Migrate to AWS SDK v2 #38576

Merged
merged 10 commits into from
Aug 7, 2024
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
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.

37 changes: 19 additions & 18 deletions internal/service/memorydb/acl.go
Original file line number Diff line number Diff line change
@@ -7,15 +7,16 @@ 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/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"
@@ -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{
@@ -90,11 +91,11 @@ 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)
_, err := conn.CreateACLWithContext(ctx, input)
log.Printf("[DEBUG] Creating MemoryDB ACL: %+v", 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{
@@ -123,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
@@ -140,22 +141,22 @@ 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[userName] = struct{}{}
}

for _, v := range oldSet.Difference(newSet).List() {
userNameToRemove := v.(string)
_, userNameStillPresent := initialUserNames[userNameToRemove]

if userNameStillPresent {
input.UserNamesToRemove = append(input.UserNamesToRemove, aws.String(userNameToRemove))
input.UserNamesToRemove = append(input.UserNamesToRemove, userNameToRemove)
}
}

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,23 +190,23 @@ 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("user_names", flex.FlattenStringSet(acl.UserNames))
d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(acl.Name)))
d.Set("user_names", flex.FlattenStringValueSet(acl.UserNames))

return diags
}

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 errs.IsA[*awstypes.ACLNotFoundFault](err) {
return diags
}

8 changes: 4 additions & 4 deletions internal/service/memorydb/acl_data_source.go
Original file line number Diff line number Diff line change
@@ -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,12 +59,12 @@ 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)
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))

4 changes: 2 additions & 2 deletions internal/service/memorydb/acl_test.go
Original file line number Diff line number Diff line change
@@ -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])

Loading