From 027d17311bc716e32d75a961c0998e6e6098149b Mon Sep 17 00:00:00 2001 From: Matt Burgess <549318+mattburgess@users.noreply.github.com> Date: Tue, 30 Apr 2024 22:18:51 +0100 Subject: [PATCH] detective: Migrate to AWS SDK v2 --- go.mod | 1 + go.sum | 2 + internal/conns/awsclient_gen.go | 6 +- internal/service/detective/generate.go | 2 +- internal/service/detective/graph.go | 59 ++++++------ internal/service/detective/graph_test.go | 14 +-- .../service/detective/invitation_accepter.go | 51 +++++----- .../detective/invitation_accepter_test.go | 4 +- internal/service/detective/member.go | 92 +++++++++---------- internal/service/detective/member_test.go | 18 ++-- .../detective/organization_admin_account.go | 65 +++++++------ .../organization_admin_account_test.go | 4 +- .../detective/organization_configuration.go | 14 +-- .../detective/service_endpoints_gen_test.go | 40 +++++--- .../service/detective/service_package_gen.go | 17 ++-- internal/service/detective/tags_gen.go | 33 ++++--- names/data/names_data.csv | 2 +- names/names.go | 1 + 18 files changed, 219 insertions(+), 206 deletions(-) diff --git a/go.mod b/go.mod index 2093b8ed8d7..2c1f560fd28 100644 --- a/go.mod +++ b/go.mod @@ -70,6 +70,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/datasync v1.37.0 github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0 github.com/aws/aws-sdk-go-v2/service/dax v1.19.4 + github.com/aws/aws-sdk-go-v2/service/detective v1.27.4 github.com/aws/aws-sdk-go-v2/service/devopsguru v1.30.4 github.com/aws/aws-sdk-go-v2/service/directoryservice v1.24.4 github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.9.3 diff --git a/go.sum b/go.sum index 0608c633287..6bffb0cc542 100644 --- a/go.sum +++ b/go.sum @@ -160,6 +160,8 @@ github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0 h1:wJ4bVNXoSTJIMfxgebI32qbx github.com/aws/aws-sdk-go-v2/service/datazone v1.8.0/go.mod h1:6UUbvwSg1ADRoK5rYXGDWjwzSyy8mElzIhVSqCXwNYE= github.com/aws/aws-sdk-go-v2/service/dax v1.19.4 h1:S3mvtYjRVVsg1R4EuV1LWZUiD72t+pfnBbK8TL7zEmo= github.com/aws/aws-sdk-go-v2/service/dax v1.19.4/go.mod h1:ZfNHbSICNHSqX4l5pJ6APeyWdgXgQg3PbuSFS2e5mCo= +github.com/aws/aws-sdk-go-v2/service/detective v1.27.4 h1:sIIaIrO3qajtFO8wToL1GwxvPvSeFnu6WSGIiD6VyO0= +github.com/aws/aws-sdk-go-v2/service/detective v1.27.4/go.mod h1:nQtuETgHoFqB/q8Yx7YIiWPgdTkrKyePtfIIgjAZDWk= github.com/aws/aws-sdk-go-v2/service/devopsguru v1.30.4 h1:qnMBNiyAPWwI9XSbtfOPr9rLZMdLFD2GAcZujMqw7Ow= github.com/aws/aws-sdk-go-v2/service/devopsguru v1.30.4/go.mod h1:+ezG+QXnBXCWFp1rCQrxyebQMM5lBAxziL4iuswpxqo= github.com/aws/aws-sdk-go-v2/service/directoryservice v1.24.4 h1:XBgx3sdaA0SoPXsZSNSUL14H0UnYnTSVArieaYNv0EI= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 3dac23527e2..adec8d654a8 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -62,6 +62,7 @@ import ( datasync_sdkv2 "github.com/aws/aws-sdk-go-v2/service/datasync" datazone_sdkv2 "github.com/aws/aws-sdk-go-v2/service/datazone" dax_sdkv2 "github.com/aws/aws-sdk-go-v2/service/dax" + detective_sdkv2 "github.com/aws/aws-sdk-go-v2/service/detective" devopsguru_sdkv2 "github.com/aws/aws-sdk-go-v2/service/devopsguru" directoryservice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/directoryservice" docdbelastic_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdbelastic" @@ -178,7 +179,6 @@ import ( databasemigrationservice_sdkv1 "github.com/aws/aws-sdk-go/service/databasemigrationservice" dataexchange_sdkv1 "github.com/aws/aws-sdk-go/service/dataexchange" datapipeline_sdkv1 "github.com/aws/aws-sdk-go/service/datapipeline" - detective_sdkv1 "github.com/aws/aws-sdk-go/service/detective" devicefarm_sdkv1 "github.com/aws/aws-sdk-go/service/devicefarm" directconnect_sdkv1 "github.com/aws/aws-sdk-go/service/directconnect" directoryservice_sdkv1 "github.com/aws/aws-sdk-go/service/directoryservice" @@ -550,8 +550,8 @@ func (c *AWSClient) DeployClient(ctx context.Context) *codedeploy_sdkv2.Client { return errs.Must(client[*codedeploy_sdkv2.Client](ctx, c, names.Deploy, make(map[string]any))) } -func (c *AWSClient) DetectiveConn(ctx context.Context) *detective_sdkv1.Detective { - return errs.Must(conn[*detective_sdkv1.Detective](ctx, c, names.Detective, make(map[string]any))) +func (c *AWSClient) DetectiveClient(ctx context.Context) *detective_sdkv2.Client { + return errs.Must(client[*detective_sdkv2.Client](ctx, c, names.Detective, make(map[string]any))) } func (c *AWSClient) DevOpsGuruClient(ctx context.Context) *devopsguru_sdkv2.Client { diff --git a/internal/service/detective/generate.go b/internal/service/detective/generate.go index 06ef30ccf6e..81b05dad227 100644 --- a/internal/service/detective/generate.go +++ b/internal/service/detective/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ServiceTagsMap -ListTags -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -KVTValues -ListTags -ServiceTagsMap -SkipTypesImp -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/detective/graph.go b/internal/service/detective/graph.go index b28ab8c996e..decaff2b4c3 100644 --- a/internal/service/detective/graph.go +++ b/internal/service/detective/graph.go @@ -8,12 +8,13 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" - "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/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "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" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -58,21 +59,21 @@ func resourceGraphCreate(ctx context.Context, d *schema.ResourceData, meta inter const ( timeout = 4 * time.Minute ) - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) input := &detective.CreateGraphInput{ Tags: getTagsIn(ctx), } - outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.CreateGraphWithContext(ctx, input) - }, detective.ErrCodeInternalServerException) + outputRaw, err := tfresource.RetryWhenIsA[*awstypes.InternalServerException](ctx, timeout, func() (interface{}, error) { + return conn.CreateGraph(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Detective Graph: %s", err) } - d.SetId(aws.StringValue(outputRaw.(*detective.CreateGraphOutput).GraphArn)) + d.SetId(aws.ToString(outputRaw.(*detective.CreateGraphOutput).GraphArn)) return append(diags, resourceGraphRead(ctx, d, meta)...) } @@ -80,7 +81,7 @@ func resourceGraphCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceGraphRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) graph, err := FindGraphByARN(ctx, conn, d.Id()) @@ -94,7 +95,7 @@ func resourceGraphRead(ctx context.Context, d *schema.ResourceData, meta interfa return sdkdiag.AppendErrorf(diags, "reading Detective Graph (%s): %s", d.Id(), err) } - d.Set("created_time", aws.TimeValue(graph.CreatedTime).Format(time.RFC3339)) + d.Set("created_time", aws.ToTime(graph.CreatedTime).Format(time.RFC3339)) d.Set("graph_arn", graph.Arn) return diags @@ -108,14 +109,14 @@ func resourceGraphUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceGraphDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) log.Printf("[DEBUG] Deleting Detective Graph: %s", d.Id()) - _, err := conn.DeleteGraphWithContext(ctx, &detective.DeleteGraphInput{ + _, err := conn.DeleteGraph(ctx, &detective.DeleteGraphInput{ GraphArn: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, detective.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } @@ -126,43 +127,41 @@ func resourceGraphDelete(ctx context.Context, d *schema.ResourceData, meta inter return diags } -func FindGraphByARN(ctx context.Context, conn *detective.Detective, arn string) (*detective.Graph, error) { +func FindGraphByARN(ctx context.Context, conn *detective.Client, arn string) (*awstypes.Graph, error) { input := &detective.ListGraphsInput{} - return findGraph(ctx, conn, input, func(v *detective.Graph) bool { - return aws.StringValue(v.Arn) == arn + return findGraph(ctx, conn, input, func(v awstypes.Graph) bool { + return aws.ToString(v.Arn) == arn }) } -func findGraph(ctx context.Context, conn *detective.Detective, input *detective.ListGraphsInput, filter tfslices.Predicate[*detective.Graph]) (*detective.Graph, error) { +func findGraph(ctx context.Context, conn *detective.Client, input *detective.ListGraphsInput, filter tfslices.Predicate[awstypes.Graph]) (*awstypes.Graph, error) { output, err := findGraphs(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findGraphs(ctx context.Context, conn *detective.Detective, input *detective.ListGraphsInput, filter tfslices.Predicate[*detective.Graph]) ([]*detective.Graph, error) { - var output []*detective.Graph +func findGraphs(ctx context.Context, conn *detective.Client, input *detective.ListGraphsInput, filter tfslices.Predicate[awstypes.Graph]) ([]awstypes.Graph, error) { + var output []awstypes.Graph + + pages := detective.NewListGraphsPaginator(conn, input) - err := conn.ListGraphsPagesWithContext(ctx, input, func(page *detective.ListGraphsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err } for _, v := range page.GraphList { - if v != nil && filter(v) { + if filter(v) { output = append(output, v) } } - - return !lastPage - }) - - if err != nil { - return nil, err } return output, nil diff --git a/internal/service/detective/graph_test.go b/internal/service/detective/graph_test.go index c43ffa2dd42..1ef73fba17a 100644 --- a/internal/service/detective/graph_test.go +++ b/internal/service/detective/graph_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -20,7 +20,7 @@ import ( func testAccGraph_basic(t *testing.T) { ctx := acctest.Context(t) - var graph detective.Graph + var graph awstypes.Graph resourceName := "aws_detective_graph.test" resource.Test(t, resource.TestCase{ @@ -47,7 +47,7 @@ func testAccGraph_basic(t *testing.T) { func testAccGraph_disappears(t *testing.T) { ctx := acctest.Context(t) - var graph detective.Graph + var graph awstypes.Graph resourceName := "aws_detective_graph.test" resource.Test(t, resource.TestCase{ @@ -70,7 +70,7 @@ func testAccGraph_disappears(t *testing.T) { func testAccGraph_tags(t *testing.T) { ctx := acctest.Context(t) - var graph detective.Graph + var graph awstypes.Graph resourceName := "aws_detective_graph.test" resource.Test(t, resource.TestCase{ @@ -116,7 +116,7 @@ func testAccGraph_tags(t *testing.T) { func testAccCheckGraphDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_detective_graph" { @@ -140,14 +140,14 @@ func testAccCheckGraphDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckGraphExists(ctx context.Context, n string, v *detective.Graph) resource.TestCheckFunc { +func testAccCheckGraphExists(ctx context.Context, n string, v *awstypes.Graph) 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).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) output, err := tfdetective.FindGraphByARN(ctx, conn, rs.Primary.ID) diff --git a/internal/service/detective/invitation_accepter.go b/internal/service/detective/invitation_accepter.go index a449919c556..80bce0bf8d4 100644 --- a/internal/service/detective/invitation_accepter.go +++ b/internal/service/detective/invitation_accepter.go @@ -7,12 +7,13 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" - "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/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "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" @@ -44,14 +45,14 @@ func ResourceInvitationAccepter() *schema.Resource { func resourceInvitationAccepterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) graphARN := d.Get("graph_arn").(string) input := &detective.AcceptInvitationInput{ GraphArn: aws.String(graphARN), } - _, err := conn.AcceptInvitationWithContext(ctx, input) + _, err := conn.AcceptInvitation(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "accepting Detective Invitation (%s): %s", graphARN, err) @@ -65,7 +66,7 @@ func resourceInvitationAccepterCreate(ctx context.Context, d *schema.ResourceDat func resourceInvitationAccepterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) member, err := FindInvitationByGraphARN(ctx, conn, d.Id()) @@ -87,14 +88,14 @@ func resourceInvitationAccepterRead(ctx context.Context, d *schema.ResourceData, func resourceInvitationAccepterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) log.Printf("[DEBUG] Deleting Detective Invitation Accepter: %s", d.Id()) - _, err := conn.DisassociateMembershipWithContext(ctx, &detective.DisassociateMembershipInput{ + _, err := conn.DisassociateMembership(ctx, &detective.DisassociateMembershipInput{ GraphArn: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, detective.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } @@ -105,43 +106,41 @@ func resourceInvitationAccepterDelete(ctx context.Context, d *schema.ResourceDat return diags } -func FindInvitationByGraphARN(ctx context.Context, conn *detective.Detective, graphARN string) (*detective.MemberDetail, error) { +func FindInvitationByGraphARN(ctx context.Context, conn *detective.Client, graphARN string) (*awstypes.MemberDetail, error) { input := &detective.ListInvitationsInput{} - return findInvitation(ctx, conn, input, func(v *detective.MemberDetail) bool { - return aws.StringValue(v.GraphArn) == graphARN + return findInvitation(ctx, conn, input, func(v awstypes.MemberDetail) bool { + return aws.ToString(v.GraphArn) == graphARN }) } -func findInvitation(ctx context.Context, conn *detective.Detective, input *detective.ListInvitationsInput, filter tfslices.Predicate[*detective.MemberDetail]) (*detective.MemberDetail, error) { +func findInvitation(ctx context.Context, conn *detective.Client, input *detective.ListInvitationsInput, filter tfslices.Predicate[awstypes.MemberDetail]) (*awstypes.MemberDetail, error) { output, err := findInvitations(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findInvitations(ctx context.Context, conn *detective.Detective, input *detective.ListInvitationsInput, filter tfslices.Predicate[*detective.MemberDetail]) ([]*detective.MemberDetail, error) { - var output []*detective.MemberDetail +func findInvitations(ctx context.Context, conn *detective.Client, input *detective.ListInvitationsInput, filter tfslices.Predicate[awstypes.MemberDetail]) ([]awstypes.MemberDetail, error) { + var output []awstypes.MemberDetail - err := conn.ListInvitationsPagesWithContext(ctx, input, func(page *detective.ListInvitationsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := detective.NewListInvitationsPaginator(conn, input) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err } for _, v := range page.Invitations { - if v != nil && filter(v) { + if filter(v) { output = append(output, v) } } - - return !lastPage - }) - - if err != nil { - return nil, err } return output, nil diff --git a/internal/service/detective/invitation_accepter_test.go b/internal/service/detective/invitation_accepter_test.go index ef588c13587..8056e534d37 100644 --- a/internal/service/detective/invitation_accepter_test.go +++ b/internal/service/detective/invitation_accepter_test.go @@ -53,7 +53,7 @@ func testAccCheckInvitationAccepterExists(ctx context.Context, n string) resourc return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) _, err := tfdetective.FindInvitationByGraphARN(ctx, conn, rs.Primary.ID) @@ -63,7 +63,7 @@ func testAccCheckInvitationAccepterExists(ctx context.Context, n string) resourc func testAccCheckInvitationAccepterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_detective_invitation_accepter" { diff --git a/internal/service/detective/member.go b/internal/service/detective/member.go index c173a9ab6a6..d22cbb52f56 100644 --- a/internal/service/detective/member.go +++ b/internal/service/detective/member.go @@ -10,13 +10,15 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" - "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/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/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" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -93,13 +95,13 @@ func ResourceMember() *schema.Resource { func resourceMemberCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) accountID := d.Get("account_id").(string) graphARN := d.Get("graph_arn").(string) id := memberCreateResourceID(graphARN, accountID) input := &detective.CreateMembersInput{ - Accounts: []*detective.Account{{ + Accounts: []awstypes.Account{{ AccountId: aws.String(accountID), EmailAddress: aws.String(d.Get("email_address").(string)), }}, @@ -107,16 +109,16 @@ func resourceMemberCreate(ctx context.Context, d *schema.ResourceData, meta inte } if v := d.Get("disable_email_notification").(bool); v { - input.DisableEmailNotification = aws.Bool(v) + input.DisableEmailNotification = v } if v, ok := d.GetOk("message"); ok { input.Message = aws.String(v.(string)) } - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { - return conn.CreateMembersWithContext(ctx, input) - }, detective.ErrCodeInternalServerException) + _, err := tfresource.RetryWhenIsA[*awstypes.InternalServerException](ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) { + return conn.CreateMembers(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Detective Member (%s): %s", id, err) @@ -134,7 +136,7 @@ func resourceMemberCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceMemberRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) graphARN, accountID, err := MemberParseResourceID(d.Id()) if err != nil { @@ -158,9 +160,9 @@ func resourceMemberRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("disabled_reason", member.DisabledReason) d.Set("email_address", member.EmailAddress) d.Set("graph_arn", member.GraphArn) - d.Set("invited_time", aws.TimeValue(member.InvitedTime).Format(time.RFC3339)) + d.Set("invited_time", aws.ToTime(member.InvitedTime).Format(time.RFC3339)) d.Set("status", member.Status) - d.Set("updated_time", aws.TimeValue(member.UpdatedTime).Format(time.RFC3339)) + d.Set("updated_time", aws.ToTime(member.UpdatedTime).Format(time.RFC3339)) d.Set("volume_usage_in_bytes", member.VolumeUsageInBytes) return diags @@ -169,7 +171,7 @@ func resourceMemberRead(ctx context.Context, d *schema.ResourceData, meta interf func resourceMemberDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) graphARN, accountID, err := MemberParseResourceID(d.Id()) if err != nil { @@ -177,12 +179,12 @@ func resourceMemberDelete(ctx context.Context, d *schema.ResourceData, meta inte } log.Printf("[DEBUG] Deleting Detective Member: %s", d.Id()) - _, err = conn.DeleteMembersWithContext(ctx, &detective.DeleteMembersInput{ - AccountIds: aws.StringSlice([]string{accountID}), + _, err = conn.DeleteMembers(ctx, &detective.DeleteMembersInput{ + AccountIds: []string{accountID}, GraphArn: aws.String(graphARN), }) - if tfawserr.ErrCodeEquals(err, detective.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } @@ -212,58 +214,56 @@ func MemberParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected graph_arn%[2]saccount_id", id, memberResourceIDSeparator) } -func FindMemberByGraphByTwoPartKey(ctx context.Context, conn *detective.Detective, graphARN, accountID string) (*detective.MemberDetail, error) { +func FindMemberByGraphByTwoPartKey(ctx context.Context, conn *detective.Client, graphARN, accountID string) (*awstypes.MemberDetail, error) { input := &detective.ListMembersInput{ GraphArn: aws.String(graphARN), } - return findMember(ctx, conn, input, func(v *detective.MemberDetail) bool { - return aws.StringValue(v.AccountId) == accountID + return findMember(ctx, conn, input, func(v awstypes.MemberDetail) bool { + return aws.ToString(v.AccountId) == accountID }) } -func findMember(ctx context.Context, conn *detective.Detective, input *detective.ListMembersInput, filter tfslices.Predicate[*detective.MemberDetail]) (*detective.MemberDetail, error) { +func findMember(ctx context.Context, conn *detective.Client, input *detective.ListMembersInput, filter tfslices.Predicate[awstypes.MemberDetail]) (*awstypes.MemberDetail, error) { output, err := findMembers(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findMembers(ctx context.Context, conn *detective.Detective, input *detective.ListMembersInput, filter tfslices.Predicate[*detective.MemberDetail]) ([]*detective.MemberDetail, error) { - var output []*detective.MemberDetail +func findMembers(ctx context.Context, conn *detective.Client, input *detective.ListMembersInput, filter tfslices.Predicate[awstypes.MemberDetail]) ([]awstypes.MemberDetail, error) { + var output []awstypes.MemberDetail - err := conn.ListMembersPagesWithContext(ctx, input, func(page *detective.ListMembersOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := detective.NewListMembersPaginator(conn, input) - for _, v := range page.MemberDetails { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, detective.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.MemberDetails { + if filter(v) { + output = append(output, v) + } + } } return output, nil } -func statusMember(ctx context.Context, conn *detective.Detective, graphARN, adminAccountID string) retry.StateRefreshFunc { +func statusMember(ctx context.Context, conn *detective.Client, graphARN, adminAccountID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindMemberByGraphByTwoPartKey(ctx, conn, graphARN, adminAccountID) @@ -275,24 +275,24 @@ func statusMember(ctx context.Context, conn *detective.Detective, graphARN, admi return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func waitMemberInvited(ctx context.Context, conn *detective.Detective, graphARN, adminAccountID string) (*detective.MemberDetail, error) { +func waitMemberInvited(ctx context.Context, conn *detective.Client, graphARN, adminAccountID string) (*awstypes.MemberDetail, error) { const ( timeout = 4 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{detective.MemberStatusVerificationInProgress}, - Target: []string{detective.MemberStatusInvited}, + Pending: enum.Slice(awstypes.MemberStatusVerificationInProgress), + Target: enum.Slice(awstypes.MemberStatusInvited), Refresh: statusMember(ctx, conn, graphARN, adminAccountID), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*detective.MemberDetail); ok { + if output, ok := outputRaw.(*awstypes.MemberDetail); ok { return output, err } diff --git a/internal/service/detective/member_test.go b/internal/service/detective/member_test.go index 13558c58892..f9b1c25a6d1 100644 --- a/internal/service/detective/member_test.go +++ b/internal/service/detective/member_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -20,7 +20,7 @@ import ( func testAccMember_basic(t *testing.T) { ctx := acctest.Context(t) - var detectiveOutput detective.MemberDetail + var detectiveOutput awstypes.MemberDetail resourceName := "aws_detective_member.test" dataSourceAlternate := "data.aws_caller_identity.member" email := testAccMemberFromEnv(t) @@ -42,7 +42,7 @@ func testAccMember_basic(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "account_id", dataSourceAlternate, "account_id"), acctest.CheckResourceAttrRFC3339(resourceName, "invited_time"), acctest.CheckResourceAttrRFC3339(resourceName, "updated_time"), - resource.TestCheckResourceAttr(resourceName, "status", detective.MemberStatusInvited), + resource.TestCheckResourceAttr(resourceName, "status", string(awstypes.MemberStatusInvited)), ), }, { @@ -58,7 +58,7 @@ func testAccMember_basic(t *testing.T) { func testAccMember_disappears(t *testing.T) { ctx := acctest.Context(t) - var detectiveOutput detective.MemberDetail + var detectiveOutput awstypes.MemberDetail resourceName := "aws_detective_member.test" email := testAccMemberFromEnv(t) @@ -85,7 +85,7 @@ func testAccMember_disappears(t *testing.T) { func testAccMember_message(t *testing.T) { ctx := acctest.Context(t) - var detectiveOutput detective.MemberDetail + var detectiveOutput awstypes.MemberDetail resourceName := "aws_detective_member.test" dataSourceAlternate := "data.aws_caller_identity.member" email := testAccMemberFromEnv(t) @@ -107,7 +107,7 @@ func testAccMember_message(t *testing.T) { resource.TestCheckResourceAttrPair(resourceName, "account_id", dataSourceAlternate, "account_id"), acctest.CheckResourceAttrRFC3339(resourceName, "invited_time"), acctest.CheckResourceAttrRFC3339(resourceName, "updated_time"), - resource.TestCheckResourceAttr(resourceName, "status", detective.MemberStatusInvited), + resource.TestCheckResourceAttr(resourceName, "status", string(awstypes.MemberStatusInvited)), ), }, { @@ -120,14 +120,14 @@ func testAccMember_message(t *testing.T) { }) } -func testAccCheckMemberExists(ctx context.Context, n string, v *detective.MemberDetail) resource.TestCheckFunc { +func testAccCheckMemberExists(ctx context.Context, n string, v *awstypes.MemberDetail) 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).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) graphARN, accountID, err := tfdetective.MemberParseResourceID(rs.Primary.ID) if err != nil { @@ -148,7 +148,7 @@ func testAccCheckMemberExists(ctx context.Context, n string, v *detective.Member func testAccCheckMemberDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_detective_member" { diff --git a/internal/service/detective/organization_admin_account.go b/internal/service/detective/organization_admin_account.go index 9fd2fe77a53..1b2c40a5bc6 100644 --- a/internal/service/detective/organization_admin_account.go +++ b/internal/service/detective/organization_admin_account.go @@ -8,13 +8,14 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" - "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/detective" + awstypes "github.com/aws/aws-sdk-go-v2/service/detective/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/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" @@ -46,14 +47,14 @@ func ResourceOrganizationAdminAccount() *schema.Resource { func resourceOrganizationAdminAccountCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) accountID := d.Get("account_id").(string) input := &detective.EnableOrganizationAdminAccountInput{ AccountId: aws.String(accountID), } - _, err := conn.EnableOrganizationAdminAccountWithContext(ctx, input) + _, err := conn.EnableOrganizationAdminAccount(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "enabling Detective Organization Admin Account (%s): %s", accountID, err) @@ -75,7 +76,7 @@ func resourceOrganizationAdminAccountCreate(ctx context.Context, d *schema.Resou func resourceOrganizationAdminAccountRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) administrator, err := FindOrganizationAdminAccountByAccountID(ctx, conn, d.Id()) @@ -97,11 +98,11 @@ func resourceOrganizationAdminAccountRead(ctx context.Context, d *schema.Resourc func resourceOrganizationAdminAccountDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) - _, err := conn.DisableOrganizationAdminAccountWithContext(ctx, &detective.DisableOrganizationAdminAccountInput{}) + _, err := conn.DisableOrganizationAdminAccount(ctx, &detective.DisableOrganizationAdminAccountInput{}) - if tfawserr.ErrCodeEquals(err, detective.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } @@ -120,50 +121,48 @@ func resourceOrganizationAdminAccountDelete(ctx context.Context, d *schema.Resou return diags } -func FindOrganizationAdminAccountByAccountID(ctx context.Context, conn *detective.Detective, accountID string) (*detective.Administrator, error) { +func FindOrganizationAdminAccountByAccountID(ctx context.Context, conn *detective.Client, accountID string) (*awstypes.Administrator, error) { input := &detective.ListOrganizationAdminAccountsInput{} - return findOrganizationAdminAccount(ctx, conn, input, func(v *detective.Administrator) bool { - return aws.StringValue(v.AccountId) == accountID + return findOrganizationAdminAccount(ctx, conn, input, func(v awstypes.Administrator) bool { + return aws.ToString(v.AccountId) == accountID }) } -func findOrganizationAdminAccount(ctx context.Context, conn *detective.Detective, input *detective.ListOrganizationAdminAccountsInput, filter tfslices.Predicate[*detective.Administrator]) (*detective.Administrator, error) { +func findOrganizationAdminAccount(ctx context.Context, conn *detective.Client, input *detective.ListOrganizationAdminAccountsInput, filter tfslices.Predicate[awstypes.Administrator]) (*awstypes.Administrator, error) { output, err := findOrganizationAdminAccounts(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findOrganizationAdminAccounts(ctx context.Context, conn *detective.Detective, input *detective.ListOrganizationAdminAccountsInput, filter tfslices.Predicate[*detective.Administrator]) ([]*detective.Administrator, error) { - var output []*detective.Administrator +func findOrganizationAdminAccounts(ctx context.Context, conn *detective.Client, input *detective.ListOrganizationAdminAccountsInput, filter tfslices.Predicate[awstypes.Administrator]) ([]awstypes.Administrator, error) { + var output []awstypes.Administrator - err := conn.ListOrganizationAdminAccountsPagesWithContext(ctx, input, func(page *detective.ListOrganizationAdminAccountsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := detective.NewListOrganizationAdminAccountsPaginator(conn, input) - for _, v := range page.Administrators { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "account is not a member of an organization") { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrMessageContains(err, detective.ErrCodeValidationException, "account is not a member of an organization") { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.Administrators { + if filter(v) { + output = append(output, v) + } + } } return output, nil diff --git a/internal/service/detective/organization_admin_account_test.go b/internal/service/detective/organization_admin_account_test.go index d67f8af0a6a..89bf9e53463 100644 --- a/internal/service/detective/organization_admin_account_test.go +++ b/internal/service/detective/organization_admin_account_test.go @@ -101,7 +101,7 @@ func testAccOrganizationAdminAccount_MultiRegion(t *testing.T) { func testAccCheckOrganizationAdminAccountDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_detective_organization_admin_account" { @@ -132,7 +132,7 @@ func testAccCheckOrganizationAdminAccountExists(ctx context.Context, n string) r return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DetectiveClient(ctx) _, err := tfdetective.FindOrganizationAdminAccountByAccountID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/detective/organization_configuration.go b/internal/service/detective/organization_configuration.go index de341b33fc8..59d4a3baa1f 100644 --- a/internal/service/detective/organization_configuration.go +++ b/internal/service/detective/organization_configuration.go @@ -6,8 +6,8 @@ package detective import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/detective" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -45,15 +45,15 @@ func ResourceOrganizationConfiguration() *schema.Resource { func resourceOrganizationConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) graphARN := d.Get("graph_arn").(string) input := &detective.UpdateOrganizationConfigurationInput{ - AutoEnable: aws.Bool(d.Get("auto_enable").(bool)), + AutoEnable: d.Get("auto_enable").(bool), GraphArn: aws.String(graphARN), } - _, err := conn.UpdateOrganizationConfigurationWithContext(ctx, input) + _, err := conn.UpdateOrganizationConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating Detective Organization Configuration (%s): %s", graphARN, err) @@ -69,13 +69,13 @@ func resourceOrganizationConfigurationUpdate(ctx context.Context, d *schema.Reso func resourceOrganizationConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DetectiveConn(ctx) + conn := meta.(*conns.AWSClient).DetectiveClient(ctx) input := &detective.DescribeOrganizationConfigurationInput{ GraphArn: aws.String(d.Id()), } - output, err := conn.DescribeOrganizationConfigurationWithContext(ctx, input) + output, err := conn.DescribeOrganizationConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading Detective Organization Configuration (%s): %s", d.Id(), err) diff --git a/internal/service/detective/service_endpoints_gen_test.go b/internal/service/detective/service_endpoints_gen_test.go index d6c57dd3294..eb81befcab8 100644 --- a/internal/service/detective/service_endpoints_gen_test.go +++ b/internal/service/detective/service_endpoints_gen_test.go @@ -4,17 +4,17 @@ package detective_test import ( "context" + "errors" "fmt" "maps" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - detective_sdkv1 "github.com/aws/aws-sdk-go/service/detective" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + detective_sdkv2 "github.com/aws/aws-sdk-go-v2/service/detective" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -212,32 +212,42 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := detective_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(detective_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), detective_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.DetectiveConn(ctx) - - req, _ := client.ListGraphsRequest(&detective_sdkv1.ListGraphsInput{}) + var endpoint string - req.HTTPRequest.URL.Path = "/" + client := meta.DetectiveClient(ctx) - endpoint := req.HTTPRequest.URL.String() + _, err := client.ListGraphs(ctx, &detective_sdkv2.ListGraphsInput{}, + func(opts *detective_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/detective/service_package_gen.go b/internal/service/detective/service_package_gen.go index 7b094cc0915..9f32384841f 100644 --- a/internal/service/detective/service_package_gen.go +++ b/internal/service/detective/service_package_gen.go @@ -5,9 +5,8 @@ package detective import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - detective_sdkv1 "github.com/aws/aws-sdk-go/service/detective" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + detective_sdkv2 "github.com/aws/aws-sdk-go-v2/service/detective" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -60,11 +59,15 @@ func (p *servicePackage) ServicePackageName() string { return names.Detective } -// 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) (*detective_sdkv1.Detective, error) { - sess := config["session"].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*detective_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return detective_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return detective_sdkv2.NewFromConfig(cfg, func(o *detective_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/detective/tags_gen.go b/internal/service/detective/tags_gen.go index 07123082e85..909dfccc944 100644 --- a/internal/service/detective/tags_gen.go +++ b/internal/service/detective/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/detective" - "github.com/aws/aws-sdk-go/service/detective/detectiveiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/detective" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +18,12 @@ import ( // listTags lists detective service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn detectiveiface.DetectiveAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *detective.Client, identifier string, optFns ...func(*detective.Options)) (tftags.KeyValueTags, error) { input := &detective.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +35,7 @@ func listTags(ctx context.Context, conn detectiveiface.DetectiveAPI, identifier // ListTags lists detective service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).DetectiveConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).DetectiveClient(ctx), identifier) if err != nil { return err @@ -49,21 +48,21 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri return nil } -// map[string]*string handling +// map[string]string handling // Tags returns detective service tags. -func Tags(tags tftags.KeyValueTags) map[string]*string { - return aws.StringMap(tags.Map()) +func Tags(tags tftags.KeyValueTags) map[string]string { + return tags.Map() } // KeyValueTags creates tftags.KeyValueTags from detective service tags. -func KeyValueTags(ctx context.Context, tags map[string]*string) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags map[string]string) tftags.KeyValueTags { return tftags.New(ctx, tags) } // getTagsIn returns detective service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) map[string]*string { +func getTagsIn(ctx context.Context) map[string]string { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -74,7 +73,7 @@ func getTagsIn(ctx context.Context) map[string]*string { } // setTagsOut sets detective service tags in Context. -func setTagsOut(ctx context.Context, tags map[string]*string) { +func setTagsOut(ctx context.Context, tags map[string]string) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -83,7 +82,7 @@ func setTagsOut(ctx context.Context, tags map[string]*string) { // updateTags updates detective 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 detectiveiface.DetectiveAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *detective.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*detective.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -94,10 +93,10 @@ func updateTags(ctx context.Context, conn detectiveiface.DetectiveAPI, identifie if len(removedTags) > 0 { input := &detective.UntagResourceInput{ ResourceArn: 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) @@ -112,7 +111,7 @@ func updateTags(ctx context.Context, conn detectiveiface.DetectiveAPI, identifie 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) @@ -125,5 +124,5 @@ func updateTags(ctx context.Context, conn detectiveiface.DetectiveAPI, identifie // UpdateTags updates detective 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).DetectiveConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).DetectiveClient(ctx), identifier, oldTags, newTags) } diff --git a/names/data/names_data.csv b/names/data/names_data.csv index c0ee031d37d..4be6de89de0 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -116,7 +116,7 @@ datazone,datazone,datazone,datazone,,datazone,,,DataZone,DataZone,,,2,,aws_dataz ,,,,,,,,,,,,,,,,,DeepComposer,AWS,x,,,,,,,,,No SDK support ,,,,,,,,,,,,,,,,,DeepLens,AWS,x,,,,,,,,,No SDK support ,,,,,,,,,,,,,,,,,DeepRacer,AWS,x,,,,,,,,,No SDK support -detective,detective,detective,detective,,detective,,,Detective,Detective,,1,,,aws_detective_,,detective_,Detective,Amazon,,,,,,,Detective,ListGraphs,, +detective,detective,detective,detective,,detective,,,Detective,Detective,,,2,,aws_detective_,,detective_,Detective,Amazon,,,,,,,Detective,ListGraphs,, devicefarm,devicefarm,devicefarm,devicefarm,,devicefarm,,,DeviceFarm,DeviceFarm,,1,,,aws_devicefarm_,,devicefarm_,Device Farm,AWS,,,,,,,Device Farm,ListDeviceInstances,, devops-guru,devopsguru,devopsguru,devopsguru,,devopsguru,,,DevOpsGuru,DevOpsGuru,,,2,,aws_devopsguru_,,devopsguru_,DevOps Guru,Amazon,,,,,,,DevOps Guru,DescribeAccountHealth,, directconnect,directconnect,directconnect,directconnect,,directconnect,,,DirectConnect,DirectConnect,,1,,aws_dx_,aws_directconnect_,,dx_,Direct Connect,AWS,,,,,,,Direct Connect,DescribeConnections,, diff --git a/names/names.go b/names/names.go index ad25c7b9d49..55ca992ff58 100644 --- a/names/names.go +++ b/names/names.go @@ -53,6 +53,7 @@ const ( CognitoIdentityEndpointID = "cognito-identity" ComprehendEndpointID = "comprehend" ConfigServiceEndpointID = "config" + DetectiveEndpointID = "api.detective" DevOpsGuruEndpointID = "devops-guru" ECREndpointID = "api.ecr" EKSEndpointID = "eks"