From c02f89899455faf3684841b7cb46d7506ef82ba3 Mon Sep 17 00:00:00 2001 From: Daniel Rieske Date: Sat, 11 May 2024 23:33:50 +0200 Subject: [PATCH 01/11] feat: migrated ram resources --- go.mod | 1 + go.sum | 2 + internal/conns/awsclient_gen.go | 6 +- internal/service/ram/consts.go | 13 -- internal/service/ram/generate.go | 2 +- internal/service/ram/principal_association.go | 53 +++---- .../service/ram/principal_association_test.go | 14 +- internal/service/ram/resource_association.go | 81 +++++----- .../service/ram/resource_association_test.go | 12 +- internal/service/ram/resource_share.go | 109 ++++++-------- .../service/ram/resource_share_accepter.go | 140 ++++++++---------- .../ram/resource_share_accepter_test.go | 10 +- .../service/ram/resource_share_data_source.go | 57 +++---- internal/service/ram/resource_share_test.go | 20 +-- .../service/ram/service_endpoints_gen_test.go | 40 +++-- internal/service/ram/service_package_gen.go | 17 ++- .../service/ram/sharing_with_organization.go | 10 +- internal/service/ram/sweep.go | 39 +++-- internal/service/ram/tags_gen.go | 30 ++-- internal/tfresource/not_found_error.go | 13 ++ names/data/names_data.csv | 2 +- tools/tfsdk2fw/go.mod | 1 + tools/tfsdk2fw/go.sum | 2 + 23 files changed, 312 insertions(+), 362 deletions(-) delete mode 100644 internal/service/ram/consts.go diff --git a/go.mod b/go.mod index f0510e9e32c..5869afe3157 100644 --- a/go.mod +++ b/go.mod @@ -131,6 +131,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/pricing v1.28.2 github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1 github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5 + github.com/aws/aws-sdk-go-v2/service/ram v1.25.5 github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5 github.com/aws/aws-sdk-go-v2/service/rds v1.78.1 github.com/aws/aws-sdk-go-v2/service/redshift v1.44.1 diff --git a/go.sum b/go.sum index 8fd4cc75ea4..45b4b8a4543 100644 --- a/go.sum +++ b/go.sum @@ -292,6 +292,8 @@ github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1 h1:TjDg29LJwoLOe53kf5TJ7te github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1/go.mod h1:GA+mlGvbl5shamVdR+zkQDrdExUQ9WAEnPlMtdiuVr8= github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5 h1:wh+eFaiLFeISAoINkD9tLOJ/rrpLPy6sVhFXkEfKvxM= github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5/go.mod h1:T789CzkMLwKq1b5MxcUfQeoUisJ6jJhciaZTtAQtUOU= +github.com/aws/aws-sdk-go-v2/service/ram v1.25.5 h1:9g8PSZ1SmvmEAIu64JjfdTj+49+CL21DI8EL5jKEd4E= +github.com/aws/aws-sdk-go-v2/service/ram v1.25.5/go.mod h1:ZDVnnA45kEAe24PtJOB3pgU0GdKeoRAJPIDCIVXal9c= github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5 h1:/HQfwoS7nNnbuyrBAqJOCHSpYBzVKENQjY2JzsCiYxs= github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5/go.mod h1:BUtbswz07qEjzGypmeUdtP53noKx1PBKAnX9Fe0Mul4= github.com/aws/aws-sdk-go-v2/service/rds v1.78.1 h1:D3XX2O6IzStNWEK2GU5EQTZVZ2r2Q4aRhWplndGIQR4= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index ede8ee662b3..16b5a6788d2 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -123,6 +123,7 @@ import ( pricing_sdkv2 "github.com/aws/aws-sdk-go-v2/service/pricing" qbusiness_sdkv2 "github.com/aws/aws-sdk-go-v2/service/qbusiness" qldb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/qldb" + ram_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ram" rbin_sdkv2 "github.com/aws/aws-sdk-go-v2/service/rbin" rds_sdkv2 "github.com/aws/aws-sdk-go-v2/service/rds" redshift_sdkv2 "github.com/aws/aws-sdk-go-v2/service/redshift" @@ -227,7 +228,6 @@ import ( outposts_sdkv1 "github.com/aws/aws-sdk-go/service/outposts" pinpoint_sdkv1 "github.com/aws/aws-sdk-go/service/pinpoint" quicksight_sdkv1 "github.com/aws/aws-sdk-go/service/quicksight" - ram_sdkv1 "github.com/aws/aws-sdk-go/service/ram" rds_sdkv1 "github.com/aws/aws-sdk-go/service/rds" redshift_sdkv1 "github.com/aws/aws-sdk-go/service/redshift" redshiftserverless_sdkv1 "github.com/aws/aws-sdk-go/service/redshiftserverless" @@ -966,8 +966,8 @@ func (c *AWSClient) QuickSightConn(ctx context.Context) *quicksight_sdkv1.QuickS return errs.Must(conn[*quicksight_sdkv1.QuickSight](ctx, c, names.QuickSight, make(map[string]any))) } -func (c *AWSClient) RAMConn(ctx context.Context) *ram_sdkv1.RAM { - return errs.Must(conn[*ram_sdkv1.RAM](ctx, c, names.RAM, make(map[string]any))) +func (c *AWSClient) RAMClient(ctx context.Context) *ram_sdkv2.Client { + return errs.Must(client[*ram_sdkv2.Client](ctx, c, names.RAM, make(map[string]any))) } func (c *AWSClient) RBinClient(ctx context.Context) *rbin_sdkv2.Client { diff --git a/internal/service/ram/consts.go b/internal/service/ram/consts.go deleted file mode 100644 index 6b8ecafab08..00000000000 --- a/internal/service/ram/consts.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package ram - -import ( - "time" -) - -const ( - resourceShareInvitationPropagationTimeout = 2 * time.Minute - resourceSharePropagationTimeout = 1 * time.Minute -) diff --git a/internal/service/ram/generate.go b/internal/service/ram/generate.go index fbcb43cbd23..717ca87de8d 100644 --- a/internal/service/ram/generate.go +++ b/internal/service/ram/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTagsInIDElem=ResourceShareArn -ServiceTagsSlice -TagInIDElem=ResourceShareArn -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTagsInIDElem=ResourceShareArn -ServiceTagsSlice -TagInIDElem=ResourceShareArn -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index dd3fb3cdbf3..c4b855d9320 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -10,15 +10,16 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" - "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/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" @@ -64,7 +65,7 @@ const ( func resourcePrincipalAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceShareARN, principal := d.Get("resource_share_arn").(string), d.Get("principal").(string) id := errs.Must(flex.FlattenResourceId([]string{resourceShareARN, principal}, principalAssociationResourceIDPartCount, false)) @@ -81,11 +82,11 @@ func resourcePrincipalAssociationCreate(ctx context.Context, d *schema.ResourceD input := &ram.AssociateResourceShareInput{ ClientToken: aws.String(sdkid.UniqueId()), - Principals: []*string{aws.String(principal)}, + Principals: []string{principal}, ResourceShareArn: aws.String(resourceShareARN), } - _, err = conn.AssociateResourceShareWithContext(ctx, input) + _, err = conn.AssociateResourceShare(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating RAM Principal Association (%s): %s", id, err) @@ -107,7 +108,7 @@ func resourcePrincipalAssociationCreate(ctx context.Context, d *schema.ResourceD func resourcePrincipalAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), principalAssociationResourceIDPartCount, false) if err != nil { @@ -135,7 +136,7 @@ func resourcePrincipalAssociationRead(ctx context.Context, d *schema.ResourceDat func resourcePrincipalAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), principalAssociationResourceIDPartCount, false) if err != nil { @@ -144,12 +145,12 @@ func resourcePrincipalAssociationDelete(ctx context.Context, d *schema.ResourceD resourceShareARN, principal := parts[0], parts[1] log.Printf("[DEBUG] Deleting RAM Principal Association: %s", d.Id()) - _, err = conn.DisassociateResourceShareWithContext(ctx, &ram.DisassociateResourceShareInput{ - Principals: []*string{aws.String(principal)}, + _, err = conn.DisassociateResourceShare(ctx, &ram.DisassociateResourceShareInput{ + Principals: []string{principal}, ResourceShareArn: aws.String(resourceShareARN), }) - if tfawserr.ErrCodeEquals(err, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.UnknownResourceException](err) { return diags } @@ -164,11 +165,11 @@ func resourcePrincipalAssociationDelete(ctx context.Context, d *schema.ResourceD return diags } -func findPrincipalAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, resourceShareARN, principal string) (*ram.ResourceShareAssociation, error) { +func findPrincipalAssociationByTwoPartKey(ctx context.Context, conn *ram.Client, resourceShareARN, principal string) (*awstypes.ResourceShareAssociation, error) { input := &ram.GetResourceShareAssociationsInput{ - AssociationType: aws.String(ram.ResourceShareAssociationTypePrincipal), + AssociationType: awstypes.ResourceShareAssociationTypePrincipal, Principal: aws.String(principal), - ResourceShareArns: aws.StringSlice([]string{resourceShareARN}), + ResourceShareArns: []string{resourceShareARN}, } output, err := findResourceShareAssociation(ctx, conn, input) @@ -177,9 +178,9 @@ func findPrincipalAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, re return nil, err } - if status := aws.StringValue(output.Status); status == ram.ResourceShareAssociationStatusDisassociated { + if status := output.Status; status == awstypes.ResourceShareAssociationStatusDisassociated { return nil, &retry.NotFoundError{ - Message: status, + Message: string(status), LastRequest: input, } } @@ -187,7 +188,7 @@ func findPrincipalAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, re return output, err } -func statusPrincipalAssociation(ctx context.Context, conn *ram.RAM, resourceShareARN, principal string) retry.StateRefreshFunc { +func statusPrincipalAssociation(ctx context.Context, conn *ram.Client, resourceShareARN, principal string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findPrincipalAssociationByTwoPartKey(ctx, conn, resourceShareARN, principal) @@ -199,17 +200,17 @@ func statusPrincipalAssociation(ctx context.Context, conn *ram.RAM, resourceShar return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitPrincipalAssociationCreated(ctx context.Context, conn *ram.RAM, resourceShareARN, principal string) (*ram.ResourceShareAssociation, error) { +func waitPrincipalAssociationCreated(ctx context.Context, conn *ram.Client, resourceShareARN, principal string) (*awstypes.ResourceShareAssociation, error) { const ( timeout = 3 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareAssociationStatusAssociating}, - Target: []string{ram.ResourceShareAssociationStatusAssociated}, + Pending: enum.Slice(awstypes.ResourceShareAssociationStatusAssociating), + Target: enum.Slice(awstypes.ResourceShareAssociationStatusAssociated), Refresh: statusPrincipalAssociation(ctx, conn, resourceShareARN, principal), Timeout: timeout, NotFoundChecks: 20, @@ -217,8 +218,8 @@ func waitPrincipalAssociationCreated(ctx context.Context, conn *ram.RAM, resourc outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShareAssociation); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } @@ -226,12 +227,12 @@ func waitPrincipalAssociationCreated(ctx context.Context, conn *ram.RAM, resourc return nil, err } -func waitPrincipalAssociationDeleted(ctx context.Context, conn *ram.RAM, resourceShareARN, principal string) (*ram.ResourceShareAssociation, error) { +func waitPrincipalAssociationDeleted(ctx context.Context, conn *ram.Client, resourceShareARN, principal string) (*awstypes.ResourceShareAssociation, error) { const ( timeout = 3 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareAssociationStatusAssociated, ram.ResourceShareAssociationStatusDisassociating}, + Pending: enum.Slice(awstypes.ResourceShareAssociationStatusAssociated, awstypes.ResourceShareAssociationStatusDisassociating), Target: []string{}, Refresh: statusPrincipalAssociation(ctx, conn, resourceShareARN, principal), Timeout: timeout, @@ -239,7 +240,7 @@ func waitPrincipalAssociationDeleted(ctx context.Context, conn *ram.RAM, resourc outputRaw, err := stateConf.WaitForStateContext(ctx) - if v, ok := outputRaw.(*ram.ResourceShareAssociation); ok { + if v, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { return v, err } diff --git a/internal/service/ram/principal_association_test.go b/internal/service/ram/principal_association_test.go index d17b95fd087..09aa9d510b4 100644 --- a/internal/service/ram/principal_association_test.go +++ b/internal/service/ram/principal_association_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccRAMPrincipalAssociation_basic(t *testing.T) { ctx := acctest.Context(t) - var association ram.ResourceShareAssociation + var association awstypes.ResourceShareAssociation resourceName := "aws_ram_principal_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -52,7 +52,7 @@ func TestAccRAMPrincipalAssociation_basic(t *testing.T) { func TestAccRAMPrincipalAssociation_AccountID(t *testing.T) { ctx := acctest.Context(t) - var association ram.ResourceShareAssociation + var association awstypes.ResourceShareAssociation resourceName := "aws_ram_principal_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -82,7 +82,7 @@ func TestAccRAMPrincipalAssociation_AccountID(t *testing.T) { func TestAccRAMPrincipalAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var association ram.ResourceShareAssociation + var association awstypes.ResourceShareAssociation resourceName := "aws_ram_principal_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -140,14 +140,14 @@ func testAccPreCheckSharingWithOrganizationEnabled(ctx context.Context, t *testi } } -func testAccCheckPrincipalAssociationExists(ctx context.Context, n string, v *ram.ResourceShareAssociation) resource.TestCheckFunc { +func testAccCheckPrincipalAssociationExists(ctx context.Context, n string, v *awstypes.ResourceShareAssociation) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) output, err := tfram.FindPrincipalAssociationByTwoPartKey(ctx, conn, rs.Primary.Attributes["resource_share_arn"], rs.Primary.Attributes["principal"]) @@ -163,7 +163,7 @@ func testAccCheckPrincipalAssociationExists(ctx context.Context, n string, v *ra func testAccCheckPrincipalAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ram_principal_association" { diff --git a/internal/service/ram/resource_association.go b/internal/service/ram/resource_association.go index c88e41fa1b5..6fbcaee6288 100644 --- a/internal/service/ram/resource_association.go +++ b/internal/service/ram/resource_association.go @@ -10,14 +10,15 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" - "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/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" @@ -60,7 +61,7 @@ const ( func resourceResourceAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceShareARN, resourceARN := d.Get("resource_share_arn").(string), d.Get(names.AttrResourceARN).(string) id := errs.Must(flex.FlattenResourceId([]string{resourceShareARN, resourceARN}, resourceAssociationResourceIDPartCount, false)) @@ -77,11 +78,11 @@ func resourceResourceAssociationCreate(ctx context.Context, d *schema.ResourceDa input := &ram.AssociateResourceShareInput{ ClientToken: aws.String(sdkid.UniqueId()), - ResourceArns: aws.StringSlice([]string{resourceARN}), + ResourceArns: []string{resourceARN}, ResourceShareArn: aws.String(resourceShareARN), } - _, err = conn.AssociateResourceShareWithContext(ctx, input) + _, err = conn.AssociateResourceShare(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating RAM Resource Association (%s): %s", id, err) @@ -98,7 +99,7 @@ func resourceResourceAssociationCreate(ctx context.Context, d *schema.ResourceDa func resourceResourceAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), resourceAssociationResourceIDPartCount, false) if err != nil { @@ -126,7 +127,7 @@ func resourceResourceAssociationRead(ctx context.Context, d *schema.ResourceData func resourceResourceAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), resourceAssociationResourceIDPartCount, false) if err != nil { @@ -135,12 +136,12 @@ func resourceResourceAssociationDelete(ctx context.Context, d *schema.ResourceDa resourceShareARN, resourceARN := parts[0], parts[1] log.Printf("[DEBUG] Deleting RAM Resource Association: %s", d.Id()) - _, err = conn.DisassociateResourceShareWithContext(ctx, &ram.DisassociateResourceShareInput{ - ResourceArns: aws.StringSlice([]string{resourceARN}), + _, err = conn.DisassociateResourceShare(ctx, &ram.DisassociateResourceShareInput{ + ResourceArns: []string{resourceARN}, ResourceShareArn: aws.String(resourceShareARN), }) - if tfawserr.ErrCodeEquals(err, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.UnknownResourceException](err) { return diags } @@ -155,11 +156,11 @@ func resourceResourceAssociationDelete(ctx context.Context, d *schema.ResourceDa return diags } -func findResourceAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, resourceShareARN, resourceARN string) (*ram.ResourceShareAssociation, error) { +func findResourceAssociationByTwoPartKey(ctx context.Context, conn *ram.Client, resourceShareARN, resourceARN string) (*awstypes.ResourceShareAssociation, error) { input := &ram.GetResourceShareAssociationsInput{ - AssociationType: aws.String(ram.ResourceShareAssociationTypeResource), + AssociationType: awstypes.ResourceShareAssociationTypeResource, ResourceArn: aws.String(resourceARN), - ResourceShareArns: aws.StringSlice([]string{resourceShareARN}), + ResourceShareArns: []string{resourceShareARN}, } output, err := findResourceShareAssociation(ctx, conn, input) @@ -168,9 +169,9 @@ func findResourceAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, res return nil, err } - if status := aws.StringValue(output.Status); status == ram.ResourceShareAssociationStatusDisassociated { + if status := output.Status; status == awstypes.ResourceShareAssociationStatusDisassociated { return nil, &retry.NotFoundError{ - Message: status, + Message: string(status), LastRequest: input, } } @@ -178,34 +179,20 @@ func findResourceAssociationByTwoPartKey(ctx context.Context, conn *ram.RAM, res return output, err } -func findResourceShareAssociation(ctx context.Context, conn *ram.RAM, input *ram.GetResourceShareAssociationsInput) (*ram.ResourceShareAssociation, error) { +func findResourceShareAssociation(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareAssociationsInput) (*awstypes.ResourceShareAssociation, error) { output, err := findResourceShareAssociations(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findResourceShareAssociations(ctx context.Context, conn *ram.RAM, input *ram.GetResourceShareAssociationsInput) ([]*ram.ResourceShareAssociation, error) { - var output []*ram.ResourceShareAssociation +func findResourceShareAssociations(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareAssociationsInput) ([]awstypes.ResourceShareAssociation, error) { + output, err := conn.GetResourceShareAssociations(ctx, input) - err := conn.GetResourceShareAssociationsPagesWithContext(ctx, input, func(page *ram.GetResourceShareAssociationsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.ResourceShareAssociations { - if v != nil { - output = append(output, v) - } - } - - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, ram.ErrCodeResourceArnNotFoundException, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -216,10 +203,10 @@ func findResourceShareAssociations(ctx context.Context, conn *ram.RAM, input *ra return nil, err } - return output, nil + return output.ResourceShareAssociations, nil } -func statusResourceAssociation(ctx context.Context, conn *ram.RAM, resourceShareARN, resourceARN string) retry.StateRefreshFunc { +func statusResourceAssociation(ctx context.Context, conn *ram.Client, resourceShareARN, resourceARN string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findResourceAssociationByTwoPartKey(ctx, conn, resourceShareARN, resourceARN) @@ -231,25 +218,25 @@ func statusResourceAssociation(ctx context.Context, conn *ram.RAM, resourceShare return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitResourceAssociationCreated(ctx context.Context, conn *ram.RAM, resourceShareARN, resourceARN string) (*ram.ResourceShareAssociation, error) { +func waitResourceAssociationCreated(ctx context.Context, conn *ram.Client, resourceShareARN, resourceARN string) (*awstypes.ResourceShareAssociation, error) { const ( timeout = 5 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareAssociationStatusAssociating}, - Target: []string{ram.ResourceShareAssociationStatusAssociated}, + Pending: enum.Slice(awstypes.ResourceShareAssociationStatusAssociating), + Target: enum.Slice(awstypes.ResourceShareAssociationStatusAssociated), Refresh: statusResourceAssociation(ctx, conn, resourceShareARN, resourceARN), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShareAssociation); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } @@ -257,12 +244,12 @@ func waitResourceAssociationCreated(ctx context.Context, conn *ram.RAM, resource return nil, err } -func waitResourceAssociationDeleted(ctx context.Context, conn *ram.RAM, resourceShareARN, resourceARN string) (*ram.ResourceShareAssociation, error) { +func waitResourceAssociationDeleted(ctx context.Context, conn *ram.Client, resourceShareARN, resourceARN string) (*awstypes.ResourceShareAssociation, error) { const ( timeout = 5 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareAssociationStatusAssociated, ram.ResourceShareAssociationStatusDisassociating}, + Pending: enum.Slice(awstypes.ResourceShareAssociationStatusAssociated, awstypes.ResourceShareAssociationStatusDisassociating), Target: []string{}, Refresh: statusResourceAssociation(ctx, conn, resourceShareARN, resourceARN), Timeout: timeout, @@ -270,8 +257,8 @@ func waitResourceAssociationDeleted(ctx context.Context, conn *ram.RAM, resource outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShareAssociation); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } diff --git a/internal/service/ram/resource_association_test.go b/internal/service/ram/resource_association_test.go index a5bd88d9baf..4584eb71d93 100644 --- a/internal/service/ram/resource_association_test.go +++ b/internal/service/ram/resource_association_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccRAMResourceAssociation_basic(t *testing.T) { ctx := acctest.Context(t) - var resourceShareAssociation ram.ResourceShareAssociation + var resourceShareAssociation awstypes.ResourceShareAssociation resourceName := "aws_ram_resource_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -49,7 +49,7 @@ func TestAccRAMResourceAssociation_basic(t *testing.T) { func TestAccRAMResourceAssociation_disappears(t *testing.T) { ctx := acctest.Context(t) - var resourceShareAssociation ram.ResourceShareAssociation + var resourceShareAssociation awstypes.ResourceShareAssociation resourceName := "aws_ram_resource_association.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -89,14 +89,14 @@ func TestAccRAMResourceAssociation_duplicate(t *testing.T) { }) } -func testAccCheckResourceAssociationExists(ctx context.Context, n string, v *ram.ResourceShareAssociation) resource.TestCheckFunc { +func testAccCheckResourceAssociationExists(ctx context.Context, n string, v *awstypes.ResourceShareAssociation) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) output, err := tfram.FindResourceAssociationByTwoPartKey(ctx, conn, rs.Primary.Attributes["resource_share_arn"], rs.Primary.Attributes[names.AttrResourceARN]) @@ -112,7 +112,7 @@ func testAccCheckResourceAssociationExists(ctx context.Context, n string, v *ram func testAccCheckResourceAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ram_resource_association" { diff --git a/internal/service/ram/resource_share.go b/internal/service/ram/resource_share.go index a649d9348fa..3bd37b89d26 100644 --- a/internal/service/ram/resource_share.go +++ b/internal/service/ram/resource_share.go @@ -9,13 +9,15 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" - "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/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/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-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -25,6 +27,10 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +const ( + resourceSharePropagationTimeout = 1 * time.Minute +) + // @SDKResource("aws_ram_resource_share", name="Resource Share") // @Tags(identifierAttribute="id") func resourceResourceShare() *schema.Resource { @@ -77,7 +83,7 @@ func resourceResourceShare() *schema.Resource { func resourceResourceShareCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) name := d.Get(names.AttrName).(string) input := &ram.CreateResourceShareInput{ @@ -87,16 +93,16 @@ func resourceResourceShareCreate(ctx context.Context, d *schema.ResourceData, me } if v, ok := d.GetOk("permission_arns"); ok && v.(*schema.Set).Len() > 0 { - input.PermissionArns = flex.ExpandStringSet(v.(*schema.Set)) + input.PermissionArns = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateResourceShareWithContext(ctx, input) + output, err := conn.CreateResourceShare(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating RAM Resource Share (%s): %s", name, err) } - d.SetId(aws.StringValue(output.ResourceShare.ResourceShareArn)) + d.SetId(aws.ToString(output.ResourceShare.ResourceShareArn)) _, err = tfresource.RetryWhenNotFound(ctx, resourceSharePropagationTimeout, func() (interface{}, error) { return findResourceShareOwnerSelfByARN(ctx, conn, d.Id()) @@ -115,7 +121,7 @@ func resourceResourceShareCreate(ctx context.Context, d *schema.ResourceData, me func resourceResourceShareRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceShare, err := findResourceShareOwnerSelfByARN(ctx, conn, d.Id()) @@ -138,28 +144,15 @@ func resourceResourceShareRead(ctx context.Context, d *schema.ResourceData, meta input := &ram.ListResourceSharePermissionsInput{ ResourceShareArn: aws.String(d.Id()), } - var permissions []*ram.ResourceSharePermissionSummary - - err = conn.ListResourceSharePermissionsPagesWithContext(ctx, input, func(page *ram.ListResourceSharePermissionsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - for _, v := range page.Permissions { - if v != nil { - permissions = append(permissions, v) - } - } - - return !lastPage - }) + output, err := conn.ListResourceSharePermissions(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s) permissions: %s", d.Id(), err) } - permissionARNs := tfslices.ApplyToAll(permissions, func(r *ram.ResourceSharePermissionSummary) string { - return aws.StringValue(r.Arn) + permissionARNs := tfslices.ApplyToAll(output.Permissions, func(r awstypes.ResourceSharePermissionSummary) string { + return aws.ToString(r.Arn) }) d.Set("permission_arns", permissionARNs) @@ -168,7 +161,7 @@ func resourceResourceShareRead(ctx context.Context, d *schema.ResourceData, meta func resourceResourceShareUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) if d.HasChanges("allow_external_principals", names.AttrName) { input := &ram.UpdateResourceShareInput{ @@ -177,7 +170,7 @@ func resourceResourceShareUpdate(ctx context.Context, d *schema.ResourceData, me ResourceShareArn: aws.String(d.Id()), } - _, err := conn.UpdateResourceShareWithContext(ctx, input) + _, err := conn.UpdateResourceShare(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating RAM Resource Share (%s): %s", d.Id(), err) @@ -189,14 +182,14 @@ func resourceResourceShareUpdate(ctx context.Context, d *schema.ResourceData, me func resourceResourceShareDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) log.Printf("[DEBUG] Deleting RAM Resource Share: %s", d.Id()) - _, err := conn.DeleteResourceShareWithContext(ctx, &ram.DeleteResourceShareInput{ + _, err := conn.DeleteResourceShare(ctx, &ram.DeleteResourceShareInput{ ResourceShareArn: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.UnknownResourceException](err) { return diags } @@ -211,10 +204,10 @@ func resourceResourceShareDelete(ctx context.Context, d *schema.ResourceData, me return diags } -func findResourceShareOwnerSelfByARN(ctx context.Context, conn *ram.RAM, arn string) (*ram.ResourceShare, error) { +func findResourceShareOwnerSelfByARN(ctx context.Context, conn *ram.Client, arn string) (*awstypes.ResourceShare, error) { input := &ram.GetResourceSharesInput{ - ResourceOwner: aws.String(ram.ResourceOwnerSelf), - ResourceShareArns: aws.StringSlice([]string{arn}), + ResourceOwner: awstypes.ResourceOwner(awstypes.ResourceOwnerSelf), + ResourceShareArns: []string{arn}, } output, err := findResourceShare(ctx, conn, input) @@ -222,9 +215,9 @@ func findResourceShareOwnerSelfByARN(ctx context.Context, conn *ram.RAM, arn str return nil, err } - if status := aws.StringValue(output.Status); status == ram.ResourceShareStatusDeleted { + if status := output.Status; status == awstypes.ResourceShareStatusDeleted { return nil, &retry.NotFoundError{ - Message: status, + Message: string(status), LastRequest: input, } } @@ -232,34 +225,20 @@ func findResourceShareOwnerSelfByARN(ctx context.Context, conn *ram.RAM, arn str return output, nil } -func findResourceShare(ctx context.Context, conn *ram.RAM, input *ram.GetResourceSharesInput) (*ram.ResourceShare, error) { +func findResourceShare(ctx context.Context, conn *ram.Client, input *ram.GetResourceSharesInput) (*awstypes.ResourceShare, error) { output, err := findResourceShares(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findResourceShares(ctx context.Context, conn *ram.RAM, input *ram.GetResourceSharesInput) ([]*ram.ResourceShare, error) { - var output []*ram.ResourceShare +func findResourceShares(ctx context.Context, conn *ram.Client, input *ram.GetResourceSharesInput) ([]awstypes.ResourceShare, error) { + output, err := conn.GetResourceShares(ctx, input) - err := conn.GetResourceSharesPagesWithContext(ctx, input, func(page *ram.GetResourceSharesOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.ResourceShares { - if v != nil { - output = append(output, v) - } - } - - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, ram.ErrCodeResourceArnNotFoundException, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -270,10 +249,10 @@ func findResourceShares(ctx context.Context, conn *ram.RAM, input *ram.GetResour return nil, err } - return output, nil + return output.ResourceShares, nil } -func statusResourceShareOwnerSelf(ctx context.Context, conn *ram.RAM, arn string) retry.StateRefreshFunc { +func statusResourceShareOwnerSelf(ctx context.Context, conn *ram.Client, arn string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findResourceShareOwnerSelfByARN(ctx, conn, arn) @@ -285,22 +264,22 @@ func statusResourceShareOwnerSelf(ctx context.Context, conn *ram.RAM, arn string return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitResourceShareOwnedBySelfActive(ctx context.Context, conn *ram.RAM, arn string, timeout time.Duration) (*ram.ResourceShare, error) { +func waitResourceShareOwnedBySelfActive(ctx context.Context, conn *ram.Client, arn string, timeout time.Duration) (*awstypes.ResourceShare, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareStatusPending}, - Target: []string{ram.ResourceShareStatusActive}, + Pending: enum.Slice(awstypes.ResourceShareStatusPending), + Target: enum.Slice(awstypes.ResourceShareStatusActive), Refresh: statusResourceShareOwnerSelf(ctx, conn, arn), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShare); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShare); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } @@ -308,9 +287,9 @@ func waitResourceShareOwnedBySelfActive(ctx context.Context, conn *ram.RAM, arn return nil, err } -func waitResourceShareOwnedBySelfDeleted(ctx context.Context, conn *ram.RAM, arn string, timeout time.Duration) (*ram.ResourceShare, error) { +func waitResourceShareOwnedBySelfDeleted(ctx context.Context, conn *ram.Client, arn string, timeout time.Duration) (*awstypes.ResourceShare, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareStatusDeleting}, + Pending: enum.Slice(awstypes.ResourceShareStatusDeleting), Target: []string{}, Refresh: statusResourceShareOwnerSelf(ctx, conn, arn), Timeout: timeout, @@ -318,8 +297,8 @@ func waitResourceShareOwnedBySelfDeleted(ctx context.Context, conn *ram.RAM, arn outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShare); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShare); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } diff --git a/internal/service/ram/resource_share_accepter.go b/internal/service/ram/resource_share_accepter.go index 76b6c775e8f..b58bdf395c1 100644 --- a/internal/service/ram/resource_share_accepter.go +++ b/internal/service/ram/resource_share_accepter.go @@ -10,14 +10,16 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" - "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/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/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/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -26,6 +28,10 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +const ( + resourceShareInvitationPropagationTimeout = 2 * time.Minute +) + // @SDKResource("aws_ram_resource_share_accepter", name="Resource Share Accepter") func resourceResourceShareAccepter() *schema.Resource { return &schema.Resource{ @@ -86,10 +92,10 @@ func resourceResourceShareAccepter() *schema.Resource { func resourceResourceShareAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) shareARN := d.Get("share_arn").(string) - maybeInvitation, err := findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx, conn, shareARN, ram.ResourceShareInvitationStatusPending) + maybeInvitation, err := findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx, conn, shareARN, string(awstypes.ResourceShareInvitationStatusPending)) if err != nil { return sdkdiag.AppendErrorf(diags, "reading pending RAM Resource Share (%s) invitation: %s", shareARN, err) @@ -99,7 +105,7 @@ func resourceResourceShareAccepterCreate(ctx context.Context, d *schema.Resource var invitationARN string if maybeInvitation.IsSome() { invitationExists = true - invitationARN = aws.StringValue(maybeInvitation.MustUnwrap().ResourceShareInvitationArn) + invitationARN = aws.ToString(maybeInvitation.MustUnwrap().ResourceShareInvitationArn) } if !invitationExists || invitationARN == "" { @@ -113,7 +119,7 @@ func resourceResourceShareAccepterCreate(ctx context.Context, d *schema.Resource ResourceShareInvitationArn: aws.String(invitationARN), } - output, err := conn.AcceptResourceShareInvitationWithContext(ctx, input) + output, err := conn.AcceptResourceShareInvitation(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "accepting RAM Resource Share (%s) invitation (%s): %s", shareARN, invitationARN, err) @@ -121,7 +127,7 @@ func resourceResourceShareAccepterCreate(ctx context.Context, d *schema.Resource d.SetId(shareARN) - invitationARN = aws.StringValue(output.ResourceShareInvitation.ResourceShareInvitationArn) + invitationARN = aws.ToString(output.ResourceShareInvitation.ResourceShareInvitationArn) if _, err := waitResourceShareInvitationAccepted(ctx, conn, invitationARN, d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for RAM Resource Share (%s) invitation (%s) accept: %s", shareARN, invitationARN, err) } @@ -140,11 +146,11 @@ func resourceResourceShareAccepterCreate(ctx context.Context, d *schema.Resource func resourceResourceShareAccepterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics accountID := meta.(*conns.AWSClient).AccountID - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) - maybeInvitation, err := findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx, conn, d.Id(), ram.ResourceShareInvitationStatusAccepted) + maybeInvitation, err := findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx, conn, d.Id(), string(awstypes.ResourceShareInvitationStatusAccepted)) - if err != nil && !tfawserr.ErrCodeEquals(err, ram.ErrCodeResourceShareInvitationArnNotFoundException) { + if err != nil && !errs.IsA[*awstypes.ResourceShareInvitationArnNotFoundException](err) { return sdkdiag.AppendErrorf(diags, "reading accepted RAM Resource Share (%s) invitation: %s", d.Id(), err) } @@ -175,9 +181,9 @@ func resourceResourceShareAccepterRead(ctx context.Context, d *schema.ResourceDa d.Set(names.AttrStatus, resourceShare.Status) input := &ram.ListResourcesInput{ - MaxResults: aws.Int64(500), - ResourceOwner: aws.String(ram.ResourceOwnerOtherAccounts), - ResourceShareArns: aws.StringSlice([]string{d.Id()}), + MaxResults: aws.Int32(500), + ResourceOwner: awstypes.ResourceOwnerOtherAccounts, + ResourceShareArns: []string{d.Id()}, } resources, err := findResources(ctx, conn, input) @@ -185,8 +191,8 @@ func resourceResourceShareAccepterRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s) resources: %s", d.Id(), err) } - resourceARNs := tfslices.ApplyToAll(resources, func(r *ram.Resource) string { - return aws.StringValue(r.Arn) + resourceARNs := tfslices.ApplyToAll(resources, func(r awstypes.Resource) string { + return aws.ToString(r.Arn) }) d.Set("resources", resourceARNs) @@ -195,7 +201,7 @@ func resourceResourceShareAccepterRead(ctx context.Context, d *schema.ResourceDa func resourceResourceShareAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) receiverAccountID := d.Get("receiver_account_id").(string) if receiverAccountID == "" { @@ -204,17 +210,17 @@ func resourceResourceShareAccepterDelete(ctx context.Context, d *schema.Resource input := &ram.DisassociateResourceShareInput{ ClientToken: aws.String(id.UniqueId()), - Principals: []*string{aws.String(receiverAccountID)}, + Principals: []string{receiverAccountID}, ResourceShareArn: aws.String(d.Id()), } - _, err := conn.DisassociateResourceShareWithContext(ctx, input) + _, err := conn.DisassociateResourceShare(ctx, input) switch { - case tfawserr.ErrCodeEquals(err, ram.ErrCodeUnknownResourceException): + case errs.IsA[*awstypes.UnknownResourceException](err): return diags - case tfawserr.ErrCodeEquals(err, ram.ErrCodeOperationNotPermittedException): + case errs.IsA[*awstypes.OperationNotPermittedException](err): log.Printf("[WARN] Resource share could not be disassociated, but continuing: %s", err) case err != nil: @@ -232,10 +238,10 @@ func resourceResourceShareIDFromARN(arn string) string { return strings.Replace(arn[strings.LastIndex(arn, ":")+1:], "resource-share/", "rs-", -1) } -func findResourceShareOwnerOtherAccountsByARN(ctx context.Context, conn *ram.RAM, arn string) (*ram.ResourceShare, error) { +func findResourceShareOwnerOtherAccountsByARN(ctx context.Context, conn *ram.Client, arn string) (*awstypes.ResourceShare, error) { input := &ram.GetResourceSharesInput{ - ResourceOwner: aws.String(ram.ResourceOwnerOtherAccounts), - ResourceShareArns: aws.StringSlice([]string{arn}), + ResourceOwner: awstypes.ResourceOwnerOtherAccounts, + ResourceShareArns: []string{arn}, } output, err := findResourceShare(ctx, conn, input) @@ -249,52 +255,38 @@ func findResourceShareOwnerOtherAccountsByARN(ctx context.Context, conn *ram.RAM return output, nil } -func findResources(ctx context.Context, conn *ram.RAM, input *ram.ListResourcesInput) ([]*ram.Resource, error) { - var output []*ram.Resource - - err := conn.ListResourcesPagesWithContext(ctx, input, func(page *ram.ListResourcesOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.Resources { - if v != nil { - output = append(output, v) - } - } - - return !lastPage - }) +func findResources(ctx context.Context, conn *ram.Client, input *ram.ListResourcesInput) ([]awstypes.Resource, error) { + output, err := conn.ListResources(ctx, input) if err != nil { return nil, err } - return output, nil + return output.Resources, nil } -func findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx context.Context, conn *ram.RAM, resourceShareARN, status string) (option.Option[*ram.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx context.Context, conn *ram.Client, resourceShareARN, status string) (option.Option[awstypes.ResourceShareInvitation], error) { input := &ram.GetResourceShareInvitationsInput{ - ResourceShareArns: aws.StringSlice([]string{resourceShareARN}), + ResourceShareArns: []string{resourceShareARN}, } - return findMaybeResourceShareInvitationRetry(ctx, conn, input, func(v *ram.ResourceShareInvitation) bool { - return aws.StringValue(v.Status) == status + return findMaybeResourceShareInvitationRetry(ctx, conn, input, func(v awstypes.ResourceShareInvitation) bool { + return string(v.Status) == status }) } -func findMaybeResourceShareInvitationByARN(ctx context.Context, conn *ram.RAM, arn string) (option.Option[*ram.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitationByARN(ctx context.Context, conn *ram.Client, arn string) (option.Option[awstypes.ResourceShareInvitation], error) { input := &ram.GetResourceShareInvitationsInput{ - ResourceShareInvitationArns: aws.StringSlice([]string{arn}), + ResourceShareInvitationArns: []string{arn}, } - return findMaybeResourceShareInvitationRetry(ctx, conn, input, tfslices.PredicateTrue[*ram.ResourceShareInvitation]()) + return findMaybeResourceShareInvitationRetry(ctx, conn, input, tfslices.PredicateTrue[awstypes.ResourceShareInvitation]()) } -func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.RAM, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*ram.ResourceShareInvitation]) (option.Option[*ram.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { // Retry for RAM resource share invitation eventual consistency. errNotFound := errors.New("not found") - var output option.Option[*ram.ResourceShareInvitation] + var output option.Option[awstypes.ResourceShareInvitation] err := tfresource.Retry(ctx, resourceShareInvitationPropagationTimeout, func() *retry.RetryError { var err error output, err = findMaybeResourceShareInvitation(ctx, conn, input, filter) @@ -315,40 +307,26 @@ func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.RAM, i } if errors.Is(err, errNotFound) { - output, err = option.None[*ram.ResourceShareInvitation](), nil + output, err = option.None[awstypes.ResourceShareInvitation](), nil } return output, err } -func findMaybeResourceShareInvitation(ctx context.Context, conn *ram.RAM, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*ram.ResourceShareInvitation]) (option.Option[*ram.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitation(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { output, err := findResourceShareInvitations(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertMaybeSinglePtrResult(output) + return tfresource.AssertMaybeSingleValueResult(output) } -func findResourceShareInvitations(ctx context.Context, conn *ram.RAM, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*ram.ResourceShareInvitation]) ([]*ram.ResourceShareInvitation, error) { - var output []*ram.ResourceShareInvitation - - err := conn.GetResourceShareInvitationsPagesWithContext(ctx, input, func(page *ram.GetResourceShareInvitationsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.ResourceShareInvitations { - if v != nil && filter(v) { - output = append(output, v) - } - } - - return !lastPage - }) +func findResourceShareInvitations(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) ([]awstypes.ResourceShareInvitation, error) { + output, err := conn.GetResourceShareInvitations(ctx, input) - if tfawserr.ErrCodeEquals(err, ram.ErrCodeResourceShareInvitationArnNotFoundException, ram.ErrCodeUnknownResourceException) { + if errs.IsA[*awstypes.ResourceShareInvitationArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -359,10 +337,10 @@ func findResourceShareInvitations(ctx context.Context, conn *ram.RAM, input *ram return nil, err } - return output, nil + return output.ResourceShareInvitations, nil } -func statusResourceShareInvitation(ctx context.Context, conn *ram.RAM, arn string) retry.StateRefreshFunc { +func statusResourceShareInvitation(ctx context.Context, conn *ram.Client, arn string) retry.StateRefreshFunc { return func() (interface{}, string, error) { maybeInvitation, err := findMaybeResourceShareInvitationByARN(ctx, conn, arn) @@ -376,30 +354,30 @@ func statusResourceShareInvitation(ctx context.Context, conn *ram.RAM, arn strin output := maybeInvitation.MustUnwrap() - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitResourceShareInvitationAccepted(ctx context.Context, conn *ram.RAM, arn string, timeout time.Duration) (*ram.ResourceShareInvitation, error) { +func waitResourceShareInvitationAccepted(ctx context.Context, conn *ram.Client, arn string, timeout time.Duration) (*awstypes.ResourceShareInvitation, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareInvitationStatusPending}, - Target: []string{ram.ResourceShareInvitationStatusAccepted}, + Pending: enum.Slice(awstypes.ResourceShareInvitationStatusPending), + Target: enum.Slice(awstypes.ResourceShareInvitationStatusAccepted), Refresh: statusResourceShareInvitation(ctx, conn, arn), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if v, ok := outputRaw.(*ram.ResourceShareInvitation); ok { + if v, ok := outputRaw.(*awstypes.ResourceShareInvitation); ok { return v, err } return nil, err } -func waitResourceShareOwnedBySelfDisassociated(ctx context.Context, conn *ram.RAM, arn string, timeout time.Duration) (*ram.ResourceShare, error) { +func waitResourceShareOwnedBySelfDisassociated(ctx context.Context, conn *ram.Client, arn string, timeout time.Duration) (*awstypes.ResourceShare, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ram.ResourceShareAssociationStatusAssociated}, + Pending: enum.Slice(awstypes.ResourceShareAssociationStatusAssociated), Target: []string{}, Refresh: statusResourceShareOwnerSelf(ctx, conn, arn), Timeout: timeout, @@ -407,8 +385,8 @@ func waitResourceShareOwnedBySelfDisassociated(ctx context.Context, conn *ram.RA outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*ram.ResourceShare); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) + if output, ok := outputRaw.(*awstypes.ResourceShare); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) return output, err } diff --git a/internal/service/ram/resource_share_accepter_test.go b/internal/service/ram/resource_share_accepter_test.go index c909a7a5f9c..a15d4b2b3aa 100644 --- a/internal/service/ram/resource_share_accepter_test.go +++ b/internal/service/ram/resource_share_accepter_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -53,7 +53,7 @@ func TestAccRAMResourceShareAccepter_basic(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "share_arn", principalAssociationResourceName, "resource_share_arn"), acctest.MatchResourceAttrRegionalARNAccountID(resourceName, "invitation_arn", "ram", `\d{12}`, regexache.MustCompile(fmt.Sprintf("resource-share-invitation/%s$", verify.UUIDRegexPattern))), resource.TestMatchResourceAttr(resourceName, "share_id", regexache.MustCompile(fmt.Sprintf(`^rs-%s$`, verify.UUIDRegexPattern))), - resource.TestCheckResourceAttr(resourceName, names.AttrStatus, ram.ResourceShareStatusActive), + resource.TestCheckResourceAttr(resourceName, names.AttrStatus, string(awstypes.ResourceShareStatusActive)), acctest.CheckResourceAttrAccountID(resourceName, "receiver_account_id"), resource.TestMatchResourceAttr(resourceName, "sender_account_id", regexache.MustCompile(`\d{12}`)), resource.TestCheckResourceAttr(resourceName, "share_name", rName), @@ -118,7 +118,7 @@ func TestAccRAMResourceShareAccepter_resourceAssociation(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "share_arn", principalAssociationResourceName, "resource_share_arn"), acctest.MatchResourceAttrRegionalARNAccountID(resourceName, "invitation_arn", "ram", `\d{12}`, regexache.MustCompile(fmt.Sprintf("resource-share-invitation/%s$", verify.UUIDRegexPattern))), resource.TestMatchResourceAttr(resourceName, "share_id", regexache.MustCompile(fmt.Sprintf(`^rs-%s$`, verify.UUIDRegexPattern))), - resource.TestCheckResourceAttr(resourceName, names.AttrStatus, ram.ResourceShareStatusActive), + resource.TestCheckResourceAttr(resourceName, names.AttrStatus, string(awstypes.ResourceShareStatusActive)), acctest.CheckResourceAttrAccountID(resourceName, "receiver_account_id"), resource.TestMatchResourceAttr(resourceName, "sender_account_id", regexache.MustCompile(`\d{12}`)), resource.TestCheckResourceAttr(resourceName, "share_name", rName), @@ -131,7 +131,7 @@ func TestAccRAMResourceShareAccepter_resourceAssociation(t *testing.T) { func testAccCheckResourceShareAccepterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ram_resource_share_accepter" { @@ -162,7 +162,7 @@ func testAccCheckResourceShareAccepterExists(ctx context.Context, n string) reso return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) _, err := tfram.FindResourceShareOwnerOtherAccountsByARN(ctx, conn, rs.Primary.ID) diff --git a/internal/service/ram/resource_share_data_source.go b/internal/service/ram/resource_share_data_source.go index 085707d6d23..d40f23c76e1 100644 --- a/internal/service/ram/resource_share_data_source.go +++ b/internal/service/ram/resource_share_data_source.go @@ -6,12 +6,13 @@ package ram import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -65,14 +66,14 @@ func dataSourceResourceShare() *schema.Resource { }, }, "resource_owner": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(ram.ResourceOwner_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.ResourceOwner](), }, "resource_share_status": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(ram.ResourceShareStatus_Values(), false), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[awstypes.ResourceShareStatus](), }, names.AttrStatus: { Type: schema.TypeString, @@ -85,11 +86,11 @@ func dataSourceResourceShare() *schema.Resource { func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) resourceOwner := d.Get("resource_owner").(string) inputG := &ram.GetResourceSharesInput{ - ResourceOwner: aws.String(resourceOwner), + ResourceOwner: awstypes.ResourceOwner(resourceOwner), } if v, ok := d.GetOk(names.AttrName); ok { @@ -101,7 +102,7 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me } if v, ok := d.GetOk("resource_share_status"); ok { - inputG.ResourceShareStatus = aws.String(v.(string)) + inputG.ResourceShareStatus = awstypes.ResourceShareStatus(v.(string)) } share, err := findResourceShare(ctx, conn, inputG) @@ -110,7 +111,7 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("RAM Resource Share", err)) } - arn := aws.StringValue(share.ResourceShareArn) + arn := aws.ToString(share.ResourceShareArn) d.SetId(arn) d.Set(names.AttrARN, arn) d.Set(names.AttrName, share.Name) @@ -120,8 +121,8 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me setTagsOut(ctx, share.Tags) inputL := &ram.ListResourcesInput{ - ResourceOwner: aws.String(resourceOwner), - ResourceShareArns: aws.StringSlice([]string{arn}), + ResourceOwner: awstypes.ResourceOwner(resourceOwner), + ResourceShareArns: []string{arn}, } resources, err := findResources(ctx, conn, inputL) @@ -129,38 +130,34 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s) resources: %s", arn, err) } - resourceARNs := tfslices.ApplyToAll(resources, func(r *ram.Resource) string { - return aws.StringValue(r.Arn) + resourceARNs := tfslices.ApplyToAll(resources, func(r awstypes.Resource) string { + return aws.ToString(r.Arn) }) d.Set("resource_arns", resourceARNs) return diags } -func expandTagFilter(tfMap map[string]interface{}) *ram.TagFilter { - if tfMap == nil { - return nil - } - - apiObject := &ram.TagFilter{} +func expandTagFilter(tfMap map[string]interface{}) awstypes.TagFilter { + apiObject := awstypes.TagFilter{} if v, ok := tfMap[names.AttrName].(string); ok && v != "" { apiObject.TagKey = aws.String(v) } if v, ok := tfMap[names.AttrValues].([]interface{}); ok && len(v) > 0 { - apiObject.TagValues = flex.ExpandStringList(v) + apiObject.TagValues = flex.ExpandStringValueList(v) } return apiObject } -func expandTagFilters(tfList []interface{}) []*ram.TagFilter { +func expandTagFilters(tfList []interface{}) []awstypes.TagFilter { if len(tfList) == 0 { return nil } - var apiObjects []*ram.TagFilter + var apiObjects []awstypes.TagFilter for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -169,13 +166,7 @@ func expandTagFilters(tfList []interface{}) []*ram.TagFilter { continue } - apiObject := expandTagFilter(tfMap) - - if apiObject == nil { - continue - } - - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, expandTagFilter(tfMap)) } return apiObjects diff --git a/internal/service/ram/resource_share_test.go b/internal/service/ram/resource_share_test.go index 4a19ecb4329..1580f92b59d 100644 --- a/internal/service/ram/resource_share_test.go +++ b/internal/service/ram/resource_share_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccRAMResourceShare_basic(t *testing.T) { ctx := acctest.Context(t) - var resourceShare ram.ResourceShare + var resourceShare awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -54,7 +54,7 @@ func TestAccRAMResourceShare_basic(t *testing.T) { func TestAccRAMResourceShare_permission(t *testing.T) { ctx := acctest.Context(t) - var resourceShare ram.ResourceShare + var resourceShare awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -86,7 +86,7 @@ func TestAccRAMResourceShare_permission(t *testing.T) { func TestAccRAMResourceShare_allowExternalPrincipals(t *testing.T) { ctx := acctest.Context(t) - var resourceShare1, resourceShare2 ram.ResourceShare + var resourceShare1, resourceShare2 awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -121,7 +121,7 @@ func TestAccRAMResourceShare_allowExternalPrincipals(t *testing.T) { func TestAccRAMResourceShare_name(t *testing.T) { ctx := acctest.Context(t) - var resourceShare1, resourceShare2 ram.ResourceShare + var resourceShare1, resourceShare2 awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -157,7 +157,7 @@ func TestAccRAMResourceShare_name(t *testing.T) { func TestAccRAMResourceShare_tags(t *testing.T) { ctx := acctest.Context(t) - var resourceShare1, resourceShare2, resourceShare3 ram.ResourceShare + var resourceShare1, resourceShare2, resourceShare3 awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -203,7 +203,7 @@ func TestAccRAMResourceShare_tags(t *testing.T) { func TestAccRAMResourceShare_disappears(t *testing.T) { ctx := acctest.Context(t) - var resourceShare ram.ResourceShare + var resourceShare awstypes.ResourceShare resourceName := "aws_ram_resource_share.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -225,14 +225,14 @@ func TestAccRAMResourceShare_disappears(t *testing.T) { }) } -func testAccCheckResourceShareExists(ctx context.Context, n string, v *ram.ResourceShare) resource.TestCheckFunc { +func testAccCheckResourceShareExists(ctx context.Context, n string, v *awstypes.ResourceShare) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) output, err := tfram.FindResourceShareOwnerSelfByARN(ctx, conn, rs.Primary.ID) @@ -248,7 +248,7 @@ func testAccCheckResourceShareExists(ctx context.Context, n string, v *ram.Resou func testAccCheckResourceShareDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).RAMConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).RAMClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_ram_resource_share" { diff --git a/internal/service/ram/service_endpoints_gen_test.go b/internal/service/ram/service_endpoints_gen_test.go index 97df2dcd536..aeb9965b754 100644 --- a/internal/service/ram/service_endpoints_gen_test.go +++ b/internal/service/ram/service_endpoints_gen_test.go @@ -4,17 +4,17 @@ package ram_test import ( "context" + "errors" "fmt" "maps" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - ram_sdkv1 "github.com/aws/aws-sdk-go/service/ram" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + ram_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ram" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -213,32 +213,42 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := ram_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(ram_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), ram_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() - client := meta.RAMConn(ctx) - - req, _ := client.ListPermissionsRequest(&ram_sdkv1.ListPermissionsInput{}) + var endpoint string - req.HTTPRequest.URL.Path = "/" + client := meta.RAMClient(ctx) - endpoint := req.HTTPRequest.URL.String() + _, err := client.ListPermissions(ctx, &ram_sdkv2.ListPermissionsInput{}, + func(opts *ram_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) + } return endpoint } diff --git a/internal/service/ram/service_package_gen.go b/internal/service/ram/service_package_gen.go index 80ca1a9a40e..adc2913a6ad 100644 --- a/internal/service/ram/service_package_gen.go +++ b/internal/service/ram/service_package_gen.go @@ -5,9 +5,8 @@ package ram import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - ram_sdkv1 "github.com/aws/aws-sdk-go/service/ram" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + ram_sdkv2 "github.com/aws/aws-sdk-go-v2/service/ram" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -71,11 +70,15 @@ func (p *servicePackage) ServicePackageName() string { return names.RAM } -// 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) (*ram_sdkv1.RAM, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*ram_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return ram_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config[names.AttrEndpoint].(string))})), nil + return ram_sdkv2.NewFromConfig(cfg, func(o *ram_sdkv2.Options) { + if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/ram/sharing_with_organization.go b/internal/service/ram/sharing_with_organization.go index ee1ac2d85ad..2e1f068b28d 100644 --- a/internal/service/ram/sharing_with_organization.go +++ b/internal/service/ram/sharing_with_organization.go @@ -9,8 +9,8 @@ import ( "log" "slices" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ram" "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" @@ -43,15 +43,15 @@ const ( func resourceSharingWithOrganizationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).RAMConn(ctx) + conn := meta.(*conns.AWSClient).RAMClient(ctx) - output, err := conn.EnableSharingWithAwsOrganizationWithContext(ctx, &ram.EnableSharingWithAwsOrganizationInput{}) + output, err := conn.EnableSharingWithAwsOrganization(ctx, &ram.EnableSharingWithAwsOrganizationInput{}) if err != nil { return sdkdiag.AppendErrorf(diags, "enabling RAM Sharing With Organization: %s", err) } - if !aws.BoolValue(output.ReturnValue) { + if !aws.ToBool(output.ReturnValue) { return sdkdiag.AppendErrorf(diags, "RAM Sharing With Organization failed") } diff --git a/internal/service/ram/sweep.go b/internal/service/ram/sweep.go index 7ed20ea7dee..464929dba21 100644 --- a/internal/service/ram/sweep.go +++ b/internal/service/ram/sweep.go @@ -7,11 +7,12 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" - "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" ) func RegisterSweepers() { @@ -27,33 +28,27 @@ func sweepResourceShares(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.RAMConn(ctx) + conn := client.RAMClient(ctx) input := &ram.GetResourceSharesInput{ - ResourceOwner: aws.String(ram.ResourceOwnerSelf), + ResourceOwner: awstypes.ResourceOwnerSelf, } sweepResources := make([]sweep.Sweepable, 0) - err = conn.GetResourceSharesPagesWithContext(ctx, input, func(page *ram.GetResourceSharesOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.ResourceShares { - if aws.StringValue(v.Status) == ram.ResourceShareStatusDeleted { - continue - } - - r := resourceResourceShare() - d := r.Data(nil) - d.SetId(aws.StringValue(v.ResourceShareArn)) + output, err := conn.GetResourceShares(ctx, input) - sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + for _, v := range output.ResourceShares { + if v.Status == awstypes.ResourceShareStatusDeleted { + continue } - return !lastPage - }) + r := resourceResourceShare() + d := r.Data(nil) + d.SetId(aws.ToString(v.ResourceShareArn)) + + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + } - if awsv1.SkipSweepError(err) { + if awsv2.SkipSweepError(err) { log.Printf("[WARN] Skipping RAM Resource Share sweep for %s: %s", region, err) return nil } diff --git a/internal/service/ram/tags_gen.go b/internal/service/ram/tags_gen.go index 15f5a63a5ef..565d64874fd 100644 --- a/internal/service/ram/tags_gen.go +++ b/internal/service/ram/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ram" - "github.com/aws/aws-sdk-go/service/ram/ramiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ram" + awstypes "github.com/aws/aws-sdk-go-v2/service/ram/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,11 +19,11 @@ import ( // []*SERVICE.Tag handling // Tags returns ram service tags. -func Tags(tags tftags.KeyValueTags) []*ram.Tag { - result := make([]*ram.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 := &ram.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -35,11 +35,11 @@ func Tags(tags tftags.KeyValueTags) []*ram.Tag { } // KeyValueTags creates tftags.KeyValueTags from ram service tags. -func KeyValueTags(ctx context.Context, tags []*ram.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) @@ -47,7 +47,7 @@ func KeyValueTags(ctx context.Context, tags []*ram.Tag) tftags.KeyValueTags { // getTagsIn returns ram service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*ram.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 @@ -58,7 +58,7 @@ func getTagsIn(ctx context.Context) []*ram.Tag { } // setTagsOut sets ram service tags in Context. -func setTagsOut(ctx context.Context, tags []*ram.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -67,7 +67,7 @@ func setTagsOut(ctx context.Context, tags []*ram.Tag) { // updateTags updates ram 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 ramiface.RAMAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *ram.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*ram.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -78,10 +78,10 @@ func updateTags(ctx context.Context, conn ramiface.RAMAPI, identifier string, ol if len(removedTags) > 0 { input := &ram.UntagResourceInput{ ResourceShareArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -96,7 +96,7 @@ func updateTags(ctx context.Context, conn ramiface.RAMAPI, identifier string, ol Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -109,5 +109,5 @@ func updateTags(ctx context.Context, conn ramiface.RAMAPI, identifier string, ol // UpdateTags updates ram 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).RAMConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).RAMClient(ctx), identifier, oldTags, newTags) } diff --git a/internal/tfresource/not_found_error.go b/internal/tfresource/not_found_error.go index 677c3b180a8..71bc4b6712d 100644 --- a/internal/tfresource/not_found_error.go +++ b/internal/tfresource/not_found_error.go @@ -132,6 +132,19 @@ func AssertMaybeSinglePtrResult[T any](a []*T) (option.Option[*T], error) { return option.Some(a[0]), nil } +// AssertMaybeSingleValueResult returns the single non-nil value in the specified slice, or `None` if the slice is empty. +// Returns a `NotFound` error otherwise. +func AssertMaybeSingleValueResult[T any](a []T) (option.Option[T], error) { + if l := len(a); l == 0 { + return option.None[T](), nil + } else if l > 1 { + return nil, NewTooManyResultsError(l, nil) + } else if v := &a[0]; v == nil { + return nil, NewEmptyResultError(nil) + } + return option.Some(a[0]), nil +} + // AssertSingleValueResult returns a pointer to the single value in the specified slice of values. // Returns a `NotFound` error otherwise. func AssertSingleValueResult[T any](a []T, fs ...FoundFunc[T]) (*T, error) { diff --git a/names/data/names_data.csv b/names/data/names_data.csv index afb9ba73024..dc55ae96566 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -293,7 +293,7 @@ qbusiness,qbusiness,qbusiness,qbusiness,,qbusiness,,,QBusiness,QBusiness,,,2,,aw qldb,qldb,qldb,qldb,,qldb,,,QLDB,QLDB,,,2,,aws_qldb_,,qldb_,QLDB (Quantum Ledger Database),Amazon,,,,,,,QLDB,ListLedgers,, qldb-session,qldbsession,qldbsession,qldbsession,,qldbsession,,,QLDBSession,QLDBSession,,1,,,aws_qldbsession_,,qldbsession_,QLDB Session,Amazon,,x,,,,,QLDB Session,,, quicksight,quicksight,quicksight,quicksight,,quicksight,,,QuickSight,QuickSight,,1,,,aws_quicksight_,,quicksight_,QuickSight,Amazon,,,,,,,QuickSight,ListDashboards,"AwsAccountId: aws_sdkv1.String(""123456789012"")", -ram,ram,ram,ram,,ram,,,RAM,RAM,,1,,,aws_ram_,,ram_,RAM (Resource Access Manager),AWS,,,,,,,RAM,ListPermissions,, +ram,ram,ram,ram,,ram,,,RAM,RAM,,,2,,aws_ram_,,ram_,RAM (Resource Access Manager),AWS,,,,,,,RAM,ListPermissions,, rds,rds,rds,rds,,rds,,,RDS,RDS,,1,2,aws_(db_|rds_),aws_rds_,,rds_;db_,RDS (Relational Database),Amazon,,,,,,,RDS,DescribeDBInstances,, rds-data,rdsdata,rdsdataservice,rdsdata,,rdsdata,,rdsdataservice,RDSData,RDSDataService,,1,,,aws_rdsdata_,,rdsdata_,RDS Data,Amazon,,x,,,,,RDS Data,,, pi,pi,pi,pi,,pi,,,PI,PI,,1,,,aws_pi_,,pi_,RDS Performance Insights (PI),Amazon,,x,,,,,PI,,, diff --git a/tools/tfsdk2fw/go.mod b/tools/tfsdk2fw/go.mod index 690efd1fdd6..4cab08a5766 100644 --- a/tools/tfsdk2fw/go.mod +++ b/tools/tfsdk2fw/go.mod @@ -153,6 +153,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/pricing v1.28.2 // indirect github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1 // indirect github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5 // indirect + github.com/aws/aws-sdk-go-v2/service/ram v1.25.5 // indirect github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5 // indirect github.com/aws/aws-sdk-go-v2/service/rds v1.78.1 // indirect github.com/aws/aws-sdk-go-v2/service/redshift v1.44.1 // indirect diff --git a/tools/tfsdk2fw/go.sum b/tools/tfsdk2fw/go.sum index 456a3665a77..201ca33133a 100644 --- a/tools/tfsdk2fw/go.sum +++ b/tools/tfsdk2fw/go.sum @@ -292,6 +292,8 @@ github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1 h1:TjDg29LJwoLOe53kf5TJ7te github.com/aws/aws-sdk-go-v2/service/qbusiness v1.6.1/go.mod h1:GA+mlGvbl5shamVdR+zkQDrdExUQ9WAEnPlMtdiuVr8= github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5 h1:wh+eFaiLFeISAoINkD9tLOJ/rrpLPy6sVhFXkEfKvxM= github.com/aws/aws-sdk-go-v2/service/qldb v1.21.5/go.mod h1:T789CzkMLwKq1b5MxcUfQeoUisJ6jJhciaZTtAQtUOU= +github.com/aws/aws-sdk-go-v2/service/ram v1.25.5 h1:9g8PSZ1SmvmEAIu64JjfdTj+49+CL21DI8EL5jKEd4E= +github.com/aws/aws-sdk-go-v2/service/ram v1.25.5/go.mod h1:ZDVnnA45kEAe24PtJOB3pgU0GdKeoRAJPIDCIVXal9c= github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5 h1:/HQfwoS7nNnbuyrBAqJOCHSpYBzVKENQjY2JzsCiYxs= github.com/aws/aws-sdk-go-v2/service/rbin v1.16.5/go.mod h1:BUtbswz07qEjzGypmeUdtP53noKx1PBKAnX9Fe0Mul4= github.com/aws/aws-sdk-go-v2/service/rds v1.78.1 h1:D3XX2O6IzStNWEK2GU5EQTZVZ2r2Q4aRhWplndGIQR4= From c1622cecbee52aba6fc84fcfab137f0d7cf3d79d Mon Sep 17 00:00:00 2001 From: Daniel Rieske Date: Sun, 12 May 2024 00:06:10 +0200 Subject: [PATCH 02/11] chore: fix linting findings --- internal/service/ram/resource_share.go | 2 +- internal/service/ram/resource_share_accepter.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/service/ram/resource_share.go b/internal/service/ram/resource_share.go index 3bd37b89d26..c0cfea51d23 100644 --- a/internal/service/ram/resource_share.go +++ b/internal/service/ram/resource_share.go @@ -206,7 +206,7 @@ func resourceResourceShareDelete(ctx context.Context, d *schema.ResourceData, me func findResourceShareOwnerSelfByARN(ctx context.Context, conn *ram.Client, arn string) (*awstypes.ResourceShare, error) { input := &ram.GetResourceSharesInput{ - ResourceOwner: awstypes.ResourceOwner(awstypes.ResourceOwnerSelf), + ResourceOwner: awstypes.ResourceOwnerSelf, ResourceShareArns: []string{arn}, } output, err := findResourceShare(ctx, conn, input) diff --git a/internal/service/ram/resource_share_accepter.go b/internal/service/ram/resource_share_accepter.go index b58bdf395c1..d58e466d0da 100644 --- a/internal/service/ram/resource_share_accepter.go +++ b/internal/service/ram/resource_share_accepter.go @@ -337,7 +337,15 @@ func findResourceShareInvitations(ctx context.Context, conn *ram.Client, input * return nil, err } - return output.ResourceShareInvitations, nil + var out []awstypes.ResourceShareInvitation + for _, v := range output.ResourceShareInvitations { + v := v + if v := v; filter(v) { + out = append(out, v) + } + } + + return out, nil } func statusResourceShareInvitation(ctx context.Context, conn *ram.Client, arn string) retry.StateRefreshFunc { From 684c385cc86ecb59189e484fb9f8fe2fd502c185 Mon Sep 17 00:00:00 2001 From: Daniel Rieske Date: Sun, 12 May 2024 00:10:49 +0200 Subject: [PATCH 03/11] fix: length validation on `principal` --- internal/service/ram/principal_association.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index c4b855d9320..cf647debc92 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -45,6 +45,7 @@ func resourcePrincipalAssociation() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.Any( + validation.StringIsNotEmpty, verify.ValidAccountID, verify.ValidARN, ), From ac71542a1d9794973a1c6a2510c707167f3d3302 Mon Sep 17 00:00:00 2001 From: Daniel Rieske Date: Mon, 13 May 2024 14:52:46 +0200 Subject: [PATCH 04/11] fix: incorrectly accepted empty arns --- internal/service/ram/principal_association.go | 1 - internal/verify/validate.go | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index cf647debc92..c4b855d9320 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -45,7 +45,6 @@ func resourcePrincipalAssociation() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.Any( - validation.StringIsNotEmpty, verify.ValidAccountID, verify.ValidARN, ), diff --git a/internal/verify/validate.go b/internal/verify/validate.go index 1655cd758bc..f98f9a48dc7 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -78,6 +78,7 @@ type ARNCheckFunc func(any, string, arn.ARN) ([]string, []error) // ValidARNCheck validates that a string value matches an ARN format with additional validation on the parsed ARN value // It must: // * Be parseable as an ARN +// * Have a non-empty value // * Have a valid partition // * Have a valid region // * Have either an empty or valid account ID @@ -92,6 +93,7 @@ func ValidARNCheck(f ...ARNCheckFunc) schema.SchemaValidateFunc { } if value == "" { + errors = append(errors, fmt.Errorf("%s cannot be empty", k)) return ws, errors } From 4e03406173dd98ef6e7585d3ac73e6ca7a5295e0 Mon Sep 17 00:00:00 2001 From: Daniel Rieske Date: Mon, 13 May 2024 15:24:03 +0200 Subject: [PATCH 05/11] fix: validARN test scenario --- internal/verify/validate_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index 449beb7339f..5a8f3641804 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -179,7 +179,8 @@ func TestValidARN(t *testing.T) { v := "" _, errors := ValidARN(v, "arn") - if len(errors) != 0 { + // Expected output "Error: arn cannot be empty" + if len(errors) == 0 { t.Fatalf("%q should not be validated as an ARN: %q", v, errors) } From fad089a9ed80c47d3ed89b5017c312367c012d68 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 09:51:47 -0400 Subject: [PATCH 06/11] Run 'make cleantidy'. --- tools/tfsdk2fw/go.mod | 11 ++++++----- tools/tfsdk2fw/go.sum | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tools/tfsdk2fw/go.mod b/tools/tfsdk2fw/go.mod index f6d572522e1..50022385fbc 100644 --- a/tools/tfsdk2fw/go.mod +++ b/tools/tfsdk2fw/go.mod @@ -18,7 +18,7 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect - github.com/aws/aws-sdk-go v1.53.0 // indirect + github.com/aws/aws-sdk-go v1.53.1 // indirect github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect github.com/aws/aws-sdk-go-v2/config v1.27.13 // indirect @@ -41,6 +41,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/appfabric v1.7.5 // indirect github.com/aws/aws-sdk-go-v2/service/appflow v1.41.5 // indirect github.com/aws/aws-sdk-go-v2/service/appintegrations v1.25.5 // indirect + github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.5 // indirect github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.5 // indirect github.com/aws/aws-sdk-go-v2/service/athena v1.40.5 // indirect github.com/aws/aws-sdk-go-v2/service/auditmanager v1.32.5 // indirect @@ -102,7 +103,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.30.6 // indirect github.com/aws/aws-sdk-go-v2/service/emr v1.39.6 // indirect github.com/aws/aws-sdk-go-v2/service/emrserverless v1.19.2 // indirect - github.com/aws/aws-sdk-go-v2/service/eventbridge v1.30.5 // indirect + github.com/aws/aws-sdk-go-v2/service/eventbridge v1.31.0 // indirect github.com/aws/aws-sdk-go-v2/service/evidently v1.19.5 // indirect github.com/aws/aws-sdk-go-v2/service/finspace v1.24.2 // indirect github.com/aws/aws-sdk-go-v2/service/firehose v1.28.7 // indirect @@ -144,7 +145,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/mwaa v1.26.6 // indirect github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.8.2 // indirect github.com/aws/aws-sdk-go-v2/service/oam v1.11.1 // indirect - github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.6 // indirect + github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.7 // indirect github.com/aws/aws-sdk-go-v2/service/osis v1.8.5 // indirect github.com/aws/aws-sdk-go-v2/service/paymentcryptography v1.10.1 // indirect github.com/aws/aws-sdk-go-v2/service/pcaconnectorad v1.5.5 // indirect @@ -193,7 +194,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/transcribe v1.37.1 // indirect github.com/aws/aws-sdk-go-v2/service/transfer v1.47.3 // indirect github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.14.0 // indirect - github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6 // indirect + github.com/aws/aws-sdk-go-v2/service/vpclattice v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/service/waf v1.20.5 // indirect github.com/aws/aws-sdk-go-v2/service/wafregional v1.21.5 // indirect github.com/aws/aws-sdk-go-v2/service/wafv2 v1.48.4 // indirect @@ -202,7 +203,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/workspacesweb v1.18.1 // indirect github.com/aws/aws-sdk-go-v2/service/xray v1.25.5 // indirect github.com/aws/smithy-go v1.20.2 // indirect - github.com/beevik/etree v1.3.0 // indirect + github.com/beevik/etree v1.4.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/cedar-policy/cedar-go v0.0.0-20240318205125-470d1fe984bb // indirect github.com/cloudflare/circl v1.3.7 // indirect diff --git a/tools/tfsdk2fw/go.sum b/tools/tfsdk2fw/go.sum index d5fe991743d..3878b24df27 100644 --- a/tools/tfsdk2fw/go.sum +++ b/tools/tfsdk2fw/go.sum @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.53.0 h1:MMo1x1ggPPxDfHMXJnQudTbGXYlD4UigUAud1DJxPVo= -github.com/aws/aws-sdk-go v1.53.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.53.1 h1:15/i0m9rE8r1q3P4ooHCfZTJtkxwG2Dwqp9JhPaVbs0= +github.com/aws/aws-sdk-go v1.53.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to= @@ -68,6 +68,8 @@ github.com/aws/aws-sdk-go-v2/service/appflow v1.41.5 h1:gB3/k2U9FfVePNNyAJjU5MYY github.com/aws/aws-sdk-go-v2/service/appflow v1.41.5/go.mod h1:EGStqkGOjo1Mm1IMelC8W3BPq6n3Qiw+aUCgYTwjV/o= github.com/aws/aws-sdk-go-v2/service/appintegrations v1.25.5 h1:ZjnTCJEgHVLsSK85NLZKC6kx08KmOYFl52G9Y4OQyOs= github.com/aws/aws-sdk-go-v2/service/appintegrations v1.25.5/go.mod h1:tvRY6xn3fG25GW4n1W76MqTViTTzVfCXKmURxXloT9o= +github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.5 h1:QXpYXqAD3Qpd7XeZjfyTOlrMVsBe5SM4s+TvFr8Bzhs= +github.com/aws/aws-sdk-go-v2/service/applicationautoscaling v1.27.5/go.mod h1:g7O+8ghAn49ysZShSpeOxIRiI0/BgPoqHwZFNKnykco= github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.5 h1:uFhS3KcdZ/9+dN/0W/smIhtoCZP6cdQqiXsR0RzCgWE= github.com/aws/aws-sdk-go-v2/service/apprunner v1.28.5/go.mod h1:HBEDVCiXAhDxrCJ8meNd1ao+PSQkkB02RfXaEuwyp6U= github.com/aws/aws-sdk-go-v2/service/athena v1.40.5 h1:NA0i0OP0EDQqmnI9zhF1zE4/MT9ZdAii2pFJdyDvvvc= @@ -190,8 +192,8 @@ github.com/aws/aws-sdk-go-v2/service/emr v1.39.6 h1:6FFt6seuRKdiIedxSHYMg2tC/zLD github.com/aws/aws-sdk-go-v2/service/emr v1.39.6/go.mod h1:7WusX+O5pwTnx2yobUO/P1C5HlBibmrQb5gKEPFjTYM= github.com/aws/aws-sdk-go-v2/service/emrserverless v1.19.2 h1:FUqD0sv/ZriloldGjCAc2jLwT4kOKKWw8y8qy6Ib1Rs= github.com/aws/aws-sdk-go-v2/service/emrserverless v1.19.2/go.mod h1:TZrahLcSXIN/kO96kvxUzfLNLH8E6t3xodv8Zv5DHGs= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.30.5 h1:8cIsFC9HskfTIrkJUk24+1HBRUetZ0wOW3rcTqN//vg= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.30.5/go.mod h1:aIINXlt2xXhMeRsyCsLDUDohI8AdDm92gY9nIB6pv0M= +github.com/aws/aws-sdk-go-v2/service/eventbridge v1.31.0 h1:WjdhWQ2n+WVNqYc2oN9zrfM04u1y6Q6OsZC2607a55Q= +github.com/aws/aws-sdk-go-v2/service/eventbridge v1.31.0/go.mod h1:aIINXlt2xXhMeRsyCsLDUDohI8AdDm92gY9nIB6pv0M= github.com/aws/aws-sdk-go-v2/service/evidently v1.19.5 h1:gDSjoeOFMMpR+dxjkRnQX8j44pFdm2FFOP1rhs9G7vA= github.com/aws/aws-sdk-go-v2/service/evidently v1.19.5/go.mod h1:ajhW/0n1t1jQKd2Kn46/99wcMj41TSPBJ3vSWocTvdE= github.com/aws/aws-sdk-go-v2/service/finspace v1.24.2 h1:4dyH+f8RutmWzqT1sScCNNa72dDteHOXN/L4MujIphE= @@ -274,8 +276,8 @@ github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.8.2 h1:C08TU/uiP+9lFaH/wxH9 github.com/aws/aws-sdk-go-v2/service/neptunegraph v1.8.2/go.mod h1:z/vZeXWTVU//C8fnX0JqhIykpNf9EqdmEIfNrU8nPyk= github.com/aws/aws-sdk-go-v2/service/oam v1.11.1 h1:JTj9z5gGzXhg4XoVdfd+RMUeg+DqvPKQa1yMpAnKJhs= github.com/aws/aws-sdk-go-v2/service/oam v1.11.1/go.mod h1:GNW8lL/rOjgXphUtGDvd9yikXGOfo51z2LBgct6XPTs= -github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.6 h1:N4jSI2xXE/KAOfU+lLgB8aoBgKb5wfCKrFZO+wdkRDM= -github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.6/go.mod h1:T7lBopPcIVR1EJOibce+6Z3cJmY8uWTEM8+i63a4rD0= +github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.7 h1:v+IQNoDYSb/uKVyYdJwLW4J+IJ8+9PWFlbfUBSF1PJI= +github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.11.7/go.mod h1:T7lBopPcIVR1EJOibce+6Z3cJmY8uWTEM8+i63a4rD0= github.com/aws/aws-sdk-go-v2/service/osis v1.8.5 h1:YbNekLy3cv7Kfq4scc9L3OrcwuaZfwXjSYBEGUMlPEc= github.com/aws/aws-sdk-go-v2/service/osis v1.8.5/go.mod h1:MHw9zAnU6CaZXqe/J1UNcxcEZLF5oXs21Efdxw0K5tY= github.com/aws/aws-sdk-go-v2/service/paymentcryptography v1.10.1 h1:1c5ZA0hDANl2Y4uooj+f/EuSU2DegLDHA7FQKXhpIGY= @@ -372,8 +374,8 @@ github.com/aws/aws-sdk-go-v2/service/transfer v1.47.3 h1:EhqwUy9cWyivUol3OItsFxU github.com/aws/aws-sdk-go-v2/service/transfer v1.47.3/go.mod h1:z3NpUj6ziVpg9XHEMdA0xpD/lgjPuZb9R/PBV6Mieb0= github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.14.0 h1:xLuRLtl2r5Xb8854TV7cnhTtqZuThvFhoOz7K1rdBXg= github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.14.0/go.mod h1:DKtR1LdOqG21jCPD/b7zMxAFxpelWoGb65rNVTpBaXs= -github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6 h1:ZJzyuwG/oxo8Usglni0OzP9hCCiFqg5EDAwAWFZIy4Y= -github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6/go.mod h1:lwuOe4SF+wdRnUrcPt1tukhJCj4gklxBV6xlD03Uo/8= +github.com/aws/aws-sdk-go-v2/service/vpclattice v1.8.0 h1:jsf+Poq3jR8AbOhc7s9MOAAVFzgsN7ci7WZcCQyS59E= +github.com/aws/aws-sdk-go-v2/service/vpclattice v1.8.0/go.mod h1:lwuOe4SF+wdRnUrcPt1tukhJCj4gklxBV6xlD03Uo/8= github.com/aws/aws-sdk-go-v2/service/waf v1.20.5 h1:ozwvMbkdhQF4jayfaGiWF0NN+0vtH1h/lGqcTuxh8iE= github.com/aws/aws-sdk-go-v2/service/waf v1.20.5/go.mod h1:QYV1XL2OQ3gnVekU5ZLMN1mgUxPFs3/CaBL4ss+cbWM= github.com/aws/aws-sdk-go-v2/service/wafregional v1.21.5 h1:XhmOvQsidvI+fkf2AiBlNXV7CYFkdtQ5zsfDq8kuv6g= @@ -390,8 +392,8 @@ github.com/aws/aws-sdk-go-v2/service/xray v1.25.5 h1:vJ2d+owzJDDdNfKd2gFZXnSfXCb github.com/aws/aws-sdk-go-v2/service/xray v1.25.5/go.mod h1:B8TaYUDF5rQxS1t3KxrMNu074VGbxxgi/2YYsUBDsbA= github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= -github.com/beevik/etree v1.3.0 h1:hQTc+pylzIKDb23yYprodCWWTt+ojFfUZyzU09a/hmU= -github.com/beevik/etree v1.3.0/go.mod h1:aiPf89g/1k3AShMVAzriilpcE4R/Vuor90y83zVZWFc= +github.com/beevik/etree v1.4.0 h1:oz1UedHRepuY3p4N5OjE0nK1WLCqtzHf25bxplKOHLs= +github.com/beevik/etree v1.4.0/go.mod h1:cyWiXwGoasx60gHvtnEh5x8+uIjUVnjWqBvEnhnqKDA= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= From f745b743903ebccb2f05dba3b50b58474651f0d0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 09:59:00 -0400 Subject: [PATCH 07/11] Revert "fix: validARN test scenario" This reverts commit 4e03406173dd98ef6e7585d3ac73e6ca7a5295e0. --- internal/verify/validate_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index 5a8f3641804..449beb7339f 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -179,8 +179,7 @@ func TestValidARN(t *testing.T) { v := "" _, errors := ValidARN(v, "arn") - // Expected output "Error: arn cannot be empty" - if len(errors) == 0 { + if len(errors) != 0 { t.Fatalf("%q should not be validated as an ARN: %q", v, errors) } From 1b29f96a0fa617f5f5ef24cbf6585d4069a9aae3 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 09:59:27 -0400 Subject: [PATCH 08/11] Revert "fix: incorrectly accepted empty arns" This reverts commit ac71542a1d9794973a1c6a2510c707167f3d3302. --- internal/service/ram/principal_association.go | 1 + internal/verify/validate.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index a7e4c02e6e5..435fa0787c6 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -46,6 +46,7 @@ func resourcePrincipalAssociation() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: validation.Any( + validation.StringIsNotEmpty, verify.ValidAccountID, verify.ValidARN, ), diff --git a/internal/verify/validate.go b/internal/verify/validate.go index f98f9a48dc7..1655cd758bc 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -78,7 +78,6 @@ type ARNCheckFunc func(any, string, arn.ARN) ([]string, []error) // ValidARNCheck validates that a string value matches an ARN format with additional validation on the parsed ARN value // It must: // * Be parseable as an ARN -// * Have a non-empty value // * Have a valid partition // * Have a valid region // * Have either an empty or valid account ID @@ -93,7 +92,6 @@ func ValidARNCheck(f ...ARNCheckFunc) schema.SchemaValidateFunc { } if value == "" { - errors = append(errors, fmt.Errorf("%s cannot be empty", k)) return ws, errors } From 9cf5ffd42e6fcf24bfa0f3b1ddea541f8d8b99f0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 10:01:52 -0400 Subject: [PATCH 09/11] r/aws_ram_principal_association: Correct 'principal' plan-time validation. --- .changelog/37450.txt | 3 +++ internal/service/ram/principal_association.go | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changelog/37450.txt diff --git a/.changelog/37450.txt b/.changelog/37450.txt new file mode 100644 index 00000000000..b7ac61bf1c7 --- /dev/null +++ b/.changelog/37450.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ram_principal_association: Correct plan-time validation of `principal` to fix `panic: unexpected format for ID parts ([...]), the following id parts indexes are blank ([1])` +``` \ No newline at end of file diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index 435fa0787c6..f25d3e0ec74 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -45,10 +45,12 @@ func resourcePrincipalAssociation() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.Any( + ValidateFunc: validation.All( validation.StringIsNotEmpty, - verify.ValidAccountID, - verify.ValidARN, + validation.Any( + verify.ValidAccountID, + verify.ValidARN, + ), ), }, "resource_share_arn": { From c5c48524ea5a2057b465d3d167d6a84c4471c9f1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 10:28:05 -0400 Subject: [PATCH 10/11] ram: Use paginators. --- internal/service/ram/principal_association.go | 6 +- .../service/ram/principal_association_test.go | 2 +- internal/service/ram/resource_association.go | 25 +++++--- internal/service/ram/resource_share.go | 39 ++++++++----- .../service/ram/resource_share_accepter.go | 58 +++++++++++-------- .../service/ram/resource_share_data_source.go | 2 +- internal/service/ram/service_package_gen.go | 2 +- internal/service/ram/sweep.go | 33 ++++++----- 8 files changed, 101 insertions(+), 66 deletions(-) diff --git a/internal/service/ram/principal_association.go b/internal/service/ram/principal_association.go index f25d3e0ec74..c2359037530 100644 --- a/internal/service/ram/principal_association.go +++ b/internal/service/ram/principal_association.go @@ -244,8 +244,10 @@ func waitPrincipalAssociationDeleted(ctx context.Context, conn *ram.Client, reso outputRaw, err := stateConf.WaitForStateContext(ctx) - if v, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { - return v, err + if output, ok := outputRaw.(*awstypes.ResourceShareAssociation); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusMessage))) + + return output, err } return nil, err diff --git a/internal/service/ram/principal_association_test.go b/internal/service/ram/principal_association_test.go index d90591fc99a..b642ac38495 100644 --- a/internal/service/ram/principal_association_test.go +++ b/internal/service/ram/principal_association_test.go @@ -180,7 +180,7 @@ func testAccCheckPrincipalAssociationDestroy(ctx context.Context) resource.TestC return err } - return fmt.Errorf("RAM Resource Association %s still exists", rs.Primary.ID) + return fmt.Errorf("RAM Principal Association %s still exists", rs.Primary.ID) } return nil diff --git a/internal/service/ram/resource_association.go b/internal/service/ram/resource_association.go index 6fbcaee6288..69e42c317c4 100644 --- a/internal/service/ram/resource_association.go +++ b/internal/service/ram/resource_association.go @@ -190,20 +190,27 @@ func findResourceShareAssociation(ctx context.Context, conn *ram.Client, input * } func findResourceShareAssociations(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareAssociationsInput) ([]awstypes.ResourceShareAssociation, error) { - output, err := conn.GetResourceShareAssociations(ctx, input) + var output []awstypes.ResourceShareAssociation - if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + pages := ram.NewGetResourceShareAssociationsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } } - } - if err != nil { - return nil, err + if err != nil { + return nil, err + } + + output = append(output, page.ResourceShareAssociations...) } - return output.ResourceShareAssociations, nil + return output, nil } func statusResourceAssociation(ctx context.Context, conn *ram.Client, resourceShareARN, resourceARN string) retry.StateRefreshFunc { diff --git a/internal/service/ram/resource_share.go b/internal/service/ram/resource_share.go index c0cfea51d23..44e5fd1f579 100644 --- a/internal/service/ram/resource_share.go +++ b/internal/service/ram/resource_share.go @@ -144,14 +144,20 @@ func resourceResourceShareRead(ctx context.Context, d *schema.ResourceData, meta input := &ram.ListResourceSharePermissionsInput{ ResourceShareArn: aws.String(d.Id()), } + var permissions []awstypes.ResourceSharePermissionSummary - output, err := conn.ListResourceSharePermissions(ctx, input) + pages := ram.NewListResourceSharePermissionsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - if err != nil { - return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s) permissions: %s", d.Id(), err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s) permissions: %s", d.Id(), err) + } + + permissions = append(permissions, page.Permissions...) } - permissionARNs := tfslices.ApplyToAll(output.Permissions, func(r awstypes.ResourceSharePermissionSummary) string { + permissionARNs := tfslices.ApplyToAll(permissions, func(r awstypes.ResourceSharePermissionSummary) string { return aws.ToString(r.Arn) }) d.Set("permission_arns", permissionARNs) @@ -236,20 +242,27 @@ func findResourceShare(ctx context.Context, conn *ram.Client, input *ram.GetReso } func findResourceShares(ctx context.Context, conn *ram.Client, input *ram.GetResourceSharesInput) ([]awstypes.ResourceShare, error) { - output, err := conn.GetResourceShares(ctx, input) + var output []awstypes.ResourceShare - if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + pages := ram.NewGetResourceSharesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.ResourceArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } } - } - if err != nil { - return nil, err + if err != nil { + return nil, err + } + + output = append(output, page.ResourceShares...) } - return output.ResourceShares, nil + return output, nil } func statusResourceShareOwnerSelf(ctx context.Context, conn *ram.Client, arn string) retry.StateRefreshFunc { diff --git a/internal/service/ram/resource_share_accepter.go b/internal/service/ram/resource_share_accepter.go index b695293f0e8..d632e623b81 100644 --- a/internal/service/ram/resource_share_accepter.go +++ b/internal/service/ram/resource_share_accepter.go @@ -256,13 +256,20 @@ func findResourceShareOwnerOtherAccountsByARN(ctx context.Context, conn *ram.Cli } func findResources(ctx context.Context, conn *ram.Client, input *ram.ListResourcesInput) ([]awstypes.Resource, error) { - output, err := conn.ListResources(ctx, input) + var output []awstypes.Resource - if err != nil { - return nil, err + pages := ram.NewListResourcesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + output = append(output, page.Resources...) } - return output.Resources, nil + return output, nil } func findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx context.Context, conn *ram.Client, resourceShareARN, status string) (option.Option[awstypes.ResourceShareInvitation], error) { @@ -270,7 +277,7 @@ func findMaybeResourceShareInvitationByResourceShareARNAndStatus(ctx context.Con ResourceShareArns: []string{resourceShareARN}, } - return findMaybeResourceShareInvitationRetry(ctx, conn, input, func(v awstypes.ResourceShareInvitation) bool { + return findMaybeResourceShareInvitationRetry(ctx, conn, input, func(v *awstypes.ResourceShareInvitation) bool { return string(v.Status) == status }) } @@ -280,10 +287,10 @@ func findMaybeResourceShareInvitationByARN(ctx context.Context, conn *ram.Client ResourceShareInvitationArns: []string{arn}, } - return findMaybeResourceShareInvitationRetry(ctx, conn, input, tfslices.PredicateTrue[awstypes.ResourceShareInvitation]()) + return findMaybeResourceShareInvitationRetry(ctx, conn, input, tfslices.PredicateTrue[*awstypes.ResourceShareInvitation]()) } -func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { // Retry for RAM resource share invitation eventual consistency. errNotFound := errors.New("not found") var output option.Option[awstypes.ResourceShareInvitation] @@ -313,7 +320,7 @@ func findMaybeResourceShareInvitationRetry(ctx context.Context, conn *ram.Client return output, err } -func findMaybeResourceShareInvitation(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { +func findMaybeResourceShareInvitation(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*awstypes.ResourceShareInvitation]) (option.Option[awstypes.ResourceShareInvitation], error) { output, err := findResourceShareInvitations(ctx, conn, input, filter) if err != nil { @@ -323,29 +330,32 @@ func findMaybeResourceShareInvitation(ctx context.Context, conn *ram.Client, inp return tfresource.AssertMaybeSingleValueResult(output) } -func findResourceShareInvitations(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[awstypes.ResourceShareInvitation]) ([]awstypes.ResourceShareInvitation, error) { - output, err := conn.GetResourceShareInvitations(ctx, input) +func findResourceShareInvitations(ctx context.Context, conn *ram.Client, input *ram.GetResourceShareInvitationsInput, filter tfslices.Predicate[*awstypes.ResourceShareInvitation]) ([]awstypes.ResourceShareInvitation, error) { + var output []awstypes.ResourceShareInvitation + + pages := ram.NewGetResourceShareInvitationsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - if errs.IsA[*awstypes.ResourceShareInvitationArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if errs.IsA[*awstypes.ResourceShareInvitationArnNotFoundException](err) || errs.IsA[*awstypes.UnknownResourceException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } } - } - if err != nil { - return nil, err - } + if err != nil { + return nil, err + } - var out []awstypes.ResourceShareInvitation - for _, v := range output.ResourceShareInvitations { - v := v - if v := v; filter(v) { - out = append(out, v) + for _, v := range page.ResourceShareInvitations { + if filter(&v) { + output = append(output, v) + } } } - return out, nil + return output, nil } func statusResourceShareInvitation(ctx context.Context, conn *ram.Client, arn string) retry.StateRefreshFunc { diff --git a/internal/service/ram/resource_share_data_source.go b/internal/service/ram/resource_share_data_source.go index d40f23c76e1..3a6edaf684b 100644 --- a/internal/service/ram/resource_share_data_source.go +++ b/internal/service/ram/resource_share_data_source.go @@ -21,7 +21,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKDataSource("aws_ram_resource_share", name="Resource Shared") +// @SDKDataSource("aws_ram_resource_share", name="Resource Share") // @Tags func dataSourceResourceShare() *schema.Resource { return &schema.Resource{ diff --git a/internal/service/ram/service_package_gen.go b/internal/service/ram/service_package_gen.go index adc2913a6ad..073f1477e84 100644 --- a/internal/service/ram/service_package_gen.go +++ b/internal/service/ram/service_package_gen.go @@ -27,7 +27,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac { Factory: dataSourceResourceShare, TypeName: "aws_ram_resource_share", - Name: "Resource Shared", + Name: "Resource Share", Tags: &types.ServicePackageResourceTags{}, }, } diff --git a/internal/service/ram/sweep.go b/internal/service/ram/sweep.go index 464929dba21..2aaf62d8ac3 100644 --- a/internal/service/ram/sweep.go +++ b/internal/service/ram/sweep.go @@ -34,27 +34,30 @@ func sweepResourceShares(region string) error { } sweepResources := make([]sweep.Sweepable, 0) - output, err := conn.GetResourceShares(ctx, input) + pages := ram.NewGetResourceSharesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range output.ResourceShares { - if v.Status == awstypes.ResourceShareStatusDeleted { - continue + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping RAM Resource Share sweep for %s: %s", region, err) + return nil } - r := resourceResourceShare() - d := r.Data(nil) - d.SetId(aws.ToString(v.ResourceShareArn)) + if err != nil { + return fmt.Errorf("error listing RAM Resource Shares (%s): %w", region, err) + } - sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) - } + for _, v := range page.ResourceShares { + if v.Status == awstypes.ResourceShareStatusDeleted { + continue + } - if awsv2.SkipSweepError(err) { - log.Printf("[WARN] Skipping RAM Resource Share sweep for %s: %s", region, err) - return nil - } + r := resourceResourceShare() + d := r.Data(nil) + d.SetId(aws.ToString(v.ResourceShareArn)) - if err != nil { - return fmt.Errorf("error listing RAM Resource Shares (%s): %w", region, err) + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + } } err = sweep.SweepOrchestrator(ctx, sweepResources) From 056ba07219d0a68d981ddd74ae1ad53c280335e7 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 14 May 2024 11:51:38 -0400 Subject: [PATCH 11/11] Additional calls to 'testAccPreCheckSharingWithOrganizationEnabled'. --- internal/service/ram/resource_association_test.go | 15 ++++++++++++--- .../ram/resource_share_data_source_test.go | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/service/ram/resource_association_test.go b/internal/service/ram/resource_association_test.go index 4584eb71d93..6a786b5a755 100644 --- a/internal/service/ram/resource_association_test.go +++ b/internal/service/ram/resource_association_test.go @@ -27,7 +27,10 @@ func TestAccRAMResourceAssociation_basic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheckSharingWithOrganizationEnabled(ctx, t) + }, ErrorCheck: acctest.ErrorCheck(t, names.RAMServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckResourceAssociationDestroy(ctx), @@ -54,7 +57,10 @@ func TestAccRAMResourceAssociation_disappears(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheckSharingWithOrganizationEnabled(ctx, t) + }, ErrorCheck: acctest.ErrorCheck(t, names.RAMServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckResourceAssociationDestroy(ctx), @@ -76,7 +82,10 @@ func TestAccRAMResourceAssociation_duplicate(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheckSharingWithOrganizationEnabled(ctx, t) + }, ErrorCheck: acctest.ErrorCheck(t, names.RAMServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckResourceAssociationDestroy(ctx), diff --git a/internal/service/ram/resource_share_data_source_test.go b/internal/service/ram/resource_share_data_source_test.go index 1324d71fbf2..aa8aa1f0308 100644 --- a/internal/service/ram/resource_share_data_source_test.go +++ b/internal/service/ram/resource_share_data_source_test.go @@ -76,7 +76,10 @@ func TestAccRAMResourceShareDataSource_resources(t *testing.T) { datasourceName := "data.aws_ram_resource_share.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheckSharingWithOrganizationEnabled(ctx, t) + }, ErrorCheck: acctest.ErrorCheck(t, names.RAMServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{