Skip to content

Commit

Permalink
Merge pull request #38576 from mattburgess/memorydb-awssdkv2-migration
Browse files Browse the repository at this point in the history
memorydb: Migrate to AWS SDK v2
  • Loading branch information
jar-b authored Aug 7, 2024
2 parents ddb0fc5 + 654296a commit 9500f75
Show file tree
Hide file tree
Showing 32 changed files with 501 additions and 454 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,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=
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.

37 changes: 19 additions & 18 deletions internal/service/memorydb/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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())

Expand All @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions internal/service/memorydb/acl_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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))

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

Expand Down
Loading

0 comments on commit 9500f75

Please sign in to comment.