diff --git a/go.mod b/go.mod index dd4ca607f7e..e6b349e1c89 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/comprehend v1.28.2 github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4 github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3 + github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2 github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3 github.com/aws/aws-sdk-go-v2/service/directoryservice v1.21.3 github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.5.3 diff --git a/go.sum b/go.sum index 3400309ca5e..7c8d40ecd1e 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4 h1:s7jPagjsA1DyZYu github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.29.4/go.mod h1:z2ipEqlHBaieu+POGuEptwkKOBhumxLZjeO7iAJqjuk= github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3 h1:ONDuYy0oFEwNvmO3kBu3JLYp9BJsxVZCLv0+L5fIArA= github.com/aws/aws-sdk-go-v2/service/connectcases v1.11.3/go.mod h1:K//ScfyKrxpEpC5VSZesWjdYtdJXCj8sCau9iSsYdMk= +github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2 h1:yHEn7sEB3i9eqqlZPcrjwWRiMiRw9TwEzHxNJTjW+OQ= +github.com/aws/aws-sdk-go-v2/service/controltower v1.7.2/go.mod h1:mir55k6nOvOHhHj93umjlFnlODrfOAt2hA3CX8a6+8Y= github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3 h1:GXyai+Ti0BoxNfMotRFDYywCGlTV5IzXMGyG4RV6oq4= github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.32.3/go.mod h1:ALbeVeoYNXakmRHRZBIpAVRXXlesm6v5jH1037hVkac= github.com/aws/aws-sdk-go-v2/service/directoryservice v1.21.3 h1:/cMlzdpSJjjwUzBDuIeazKQtYB2VDOqCSV3zq1sDpzg= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index e661b0b4a91..602ae8f2cd1 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -25,6 +25,7 @@ import ( comprehend_sdkv2 "github.com/aws/aws-sdk-go-v2/service/comprehend" computeoptimizer_sdkv2 "github.com/aws/aws-sdk-go-v2/service/computeoptimizer" connectcases_sdkv2 "github.com/aws/aws-sdk-go-v2/service/connectcases" + controltower_sdkv2 "github.com/aws/aws-sdk-go-v2/service/controltower" customerprofiles_sdkv2 "github.com/aws/aws-sdk-go-v2/service/customerprofiles" directoryservice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/directoryservice" docdbelastic_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdbelastic" @@ -118,7 +119,6 @@ import ( cognitoidentityprovider_sdkv1 "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" configservice_sdkv1 "github.com/aws/aws-sdk-go/service/configservice" connect_sdkv1 "github.com/aws/aws-sdk-go/service/connect" - controltower_sdkv1 "github.com/aws/aws-sdk-go/service/controltower" costandusagereportservice_sdkv1 "github.com/aws/aws-sdk-go/service/costandusagereportservice" costexplorer_sdkv1 "github.com/aws/aws-sdk-go/service/costexplorer" databasemigrationservice_sdkv1 "github.com/aws/aws-sdk-go/service/databasemigrationservice" @@ -446,8 +446,8 @@ func (c *AWSClient) ConnectCasesClient(ctx context.Context) *connectcases_sdkv2. return errs.Must(client[*connectcases_sdkv2.Client](ctx, c, names.ConnectCases)) } -func (c *AWSClient) ControlTowerConn(ctx context.Context) *controltower_sdkv1.ControlTower { - return errs.Must(conn[*controltower_sdkv1.ControlTower](ctx, c, names.ControlTower)) +func (c *AWSClient) ControlTowerClient(ctx context.Context) *controltower_sdkv2.Client { + return errs.Must(client[*controltower_sdkv2.Client](ctx, c, names.ControlTower)) } func (c *AWSClient) CustomerProfilesClient(ctx context.Context) *customerprofiles_sdkv2.Client { diff --git a/internal/service/controltower/control.go b/internal/service/controltower/control.go index aa331ba4b36..2be63120ad0 100644 --- a/internal/service/controltower/control.go +++ b/internal/service/controltower/control.go @@ -6,24 +6,26 @@ package controltower import ( "context" "errors" - "fmt" "log" - "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/controltower" - "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/controltower" + "github.com/aws/aws-sdk-go-v2/service/controltower/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/flex" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKResource("aws_controltower_control") -func ResourceControl() *schema.Resource { +// @SDKResource("aws_controltower_control", name="Control") +func resourceControl() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceControlCreate, ReadWithoutTimeout: resourceControlRead, @@ -56,17 +58,17 @@ func ResourceControl() *schema.Resource { } func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) controlIdentifier := d.Get("control_identifier").(string) targetIdentifier := d.Get("target_identifier").(string) - id := ControlCreateResourceID(targetIdentifier, controlIdentifier) + id := errs.Must(flex.FlattenResourceId([]string{targetIdentifier, controlIdentifier}, controlResourceIDPartCount, false)) input := &controltower.EnableControlInput{ ControlIdentifier: aws.String(controlIdentifier), TargetIdentifier: aws.String(targetIdentifier), } - output, err := conn.EnableControlWithContext(ctx, input) + output, err := conn.EnableControl(ctx, input) if err != nil { return diag.Errorf("creating ControlTower Control (%s): %s", id, err) @@ -74,7 +76,7 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int d.SetId(id) - if _, err := waitOperationSucceeded(ctx, conn, aws.StringValue(output.OperationIdentifier), d.Timeout(schema.TimeoutCreate)); err != nil { + if _, err := waitOperationSucceeded(ctx, conn, aws.ToString(output.OperationIdentifier), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("waiting for ControlTower Control (%s) create: %s", d.Id(), err) } @@ -82,15 +84,15 @@ func resourceControlCreate(ctx context.Context, d *schema.ResourceData, meta int } func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) - - targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) + parts, err := flex.ExpandResourceId(d.Id(), controlResourceIDPartCount, false) if err != nil { return diag.FromErr(err) } - output, err := FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + targetIdentifier, controlIdentifier := parts[0], parts[1] + output, err := findEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] ControlTower Control %s not found, removing from state", d.Id()) @@ -109,16 +111,17 @@ func resourceControlRead(ctx context.Context, d *schema.ResourceData, meta inter } func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) - - targetIdentifier, controlIdentifier, err := ControlParseResourceID(d.Id()) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) + parts, err := flex.ExpandResourceId(d.Id(), controlResourceIDPartCount, false) if err != nil { return diag.FromErr(err) } + targetIdentifier, controlIdentifier := parts[0], parts[1] + log.Printf("[DEBUG] Deleting ControlTower Control: %s", d.Id()) - output, err := conn.DisableControlWithContext(ctx, &controltower.DisableControlInput{ + output, err := conn.DisableControl(ctx, &controltower.DisableControlInput{ ControlIdentifier: aws.String(controlIdentifier), TargetIdentifier: aws.String(targetIdentifier), }) @@ -127,84 +130,74 @@ func resourceControlDelete(ctx context.Context, d *schema.ResourceData, meta int return diag.Errorf("deleting ControlTower Control (%s): %s", d.Id(), err) } - if _, err := waitOperationSucceeded(ctx, conn, aws.StringValue(output.OperationIdentifier), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitOperationSucceeded(ctx, conn, aws.ToString(output.OperationIdentifier), d.Timeout(schema.TimeoutDelete)); err != nil { return diag.Errorf("waiting for ControlTower Control (%s) delete: %s", d.Id(), err) } return nil } -const controlResourceIDSeparator = "," +const ( + controlResourceIDPartCount = 2 +) -func ControlCreateResourceID(targetIdentifier, controlIdentifier string) string { - parts := []string{targetIdentifier, controlIdentifier} - id := strings.Join(parts, controlResourceIDSeparator) +func findEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.Client, targetIdentifier, controlIdentifier string) (*types.EnabledControlSummary, error) { + input := &controltower.ListEnabledControlsInput{ + TargetIdentifier: aws.String(targetIdentifier), + } - return id + return findEnabledControl(ctx, conn, input, func(v *types.EnabledControlSummary) bool { + return aws.ToString(v.ControlIdentifier) == controlIdentifier + }) } -func ControlParseResourceID(id string) (string, string, error) { - parts := strings.Split(id, controlResourceIDSeparator) +func findEnabledControl(ctx context.Context, conn *controltower.Client, input *controltower.ListEnabledControlsInput, filter tfslices.Predicate[*types.EnabledControlSummary]) (*types.EnabledControlSummary, error) { + output, err := findEnabledControls(ctx, conn, input, filter) - if len(parts) == 2 && parts[0] != "" && parts[1] != "" { - return parts[0], parts[1], nil + if err != nil { + return nil, err } - return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected TargetIdentifier%[2]sControlIdentifier", id, controlResourceIDSeparator) + return tfresource.AssertSinglePtrResult(output) } -func FindEnabledControlByTwoPartKey(ctx context.Context, conn *controltower.ControlTower, targetIdentifier, controlIdentifier string) (*controltower.EnabledControlSummary, error) { - input := &controltower.ListEnabledControlsInput{ - TargetIdentifier: aws.String(targetIdentifier), - } - var output *controltower.EnabledControlSummary - - err := conn.ListEnabledControlsPagesWithContext(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.EnabledControls { - if v == nil { - continue - } +func findEnabledControls(ctx context.Context, conn *controltower.Client, input *controltower.ListEnabledControlsInput, filter tfslices.Predicate[*types.EnabledControlSummary]) ([]*types.EnabledControlSummary, error) { + var output []*types.EnabledControlSummary - if aws.StringValue(v.ControlIdentifier) == controlIdentifier { - output = v + pages := controltower.NewListEnabledControlsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - return false + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, controltower.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err - } - - if output == nil { - return nil, tfresource.NewEmptyResultError(input) + for _, v := range page.EnabledControls { + v := v + if v := &v; filter(v) { + output = append(output, v) + } + } } return output, nil } -func findControlOperationByID(ctx context.Context, conn *controltower.ControlTower, id string) (*controltower.ControlOperation, error) { +func findControlOperationByID(ctx context.Context, conn *controltower.Client, id string) (*types.ControlOperation, error) { input := &controltower.GetControlOperationInput{ OperationIdentifier: aws.String(id), } - output, err := conn.GetControlOperationWithContext(ctx, input) + output, err := conn.GetControlOperation(ctx, input) - if tfawserr.ErrCodeEquals(err, controltower.ErrCodeResourceNotFoundException) { + if errs.IsA[*types.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -222,7 +215,7 @@ func findControlOperationByID(ctx context.Context, conn *controltower.ControlTow return output.ControlOperation, nil } -func statusControlOperation(ctx context.Context, conn *controltower.ControlTower, id string) retry.StateRefreshFunc { +func statusControlOperation(ctx context.Context, conn *controltower.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findControlOperationByID(ctx, conn, id) @@ -234,26 +227,24 @@ func statusControlOperation(ctx context.Context, conn *controltower.ControlTower return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString((*string)(&output.Status)), nil } } -func waitOperationSucceeded(ctx context.Context, conn *controltower.ControlTower, id string, timeout time.Duration) (*controltower.ControlOperation, error) { //nolint:unparam +func waitOperationSucceeded(ctx context.Context, conn *controltower.Client, id string, timeout time.Duration) (*types.ControlOperation, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ - Pending: []string{controltower.ControlOperationStatusInProgress}, - Target: []string{controltower.ControlOperationStatusSucceeded}, + Pending: enum.Slice(types.ControlOperationStatusInProgress), + Target: enum.Slice(types.ControlOperationStatusSucceeded), Refresh: statusControlOperation(ctx, conn, id), Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*controltower.ControlOperation); ok { - if status := aws.StringValue(output.Status); status == controltower.ControlOperationStatusFailed { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.StatusMessage))) - } + if output, ok := outputRaw.(*controltower.GetControlOperationOutput); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.ControlOperation.StatusMessage))) - return output, err + return output.ControlOperation, err } return nil, err diff --git a/internal/service/controltower/control_test.go b/internal/service/controltower/control_test.go index 0ac8c1fcde3..60843a9b507 100644 --- a/internal/service/controltower/control_test.go +++ b/internal/service/controltower/control_test.go @@ -8,13 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/controltower" + types "github.com/aws/aws-sdk-go-v2/service/controltower/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfcontroltower "github.com/hashicorp/terraform-provider-aws/internal/service/controltower" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccControlTowerControl_serial(t *testing.T) { @@ -32,7 +33,7 @@ func TestAccControlTowerControl_serial(t *testing.T) { func testAccControl_basic(t *testing.T) { ctx := acctest.Context(t) - var control controltower.EnabledControlSummary + var control types.EnabledControlSummary resourceName := "aws_controltower_control.test" controlName := "AWS-GR_EC2_VOLUME_INUSE_CHECK" ouName := "Security" @@ -43,7 +44,7 @@ func testAccControl_basic(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), CheckDestroy: testAccCheckControlDestroy(ctx), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ @@ -60,7 +61,7 @@ func testAccControl_basic(t *testing.T) { func testAccControl_disappears(t *testing.T) { ctx := acctest.Context(t) - var control controltower.EnabledControlSummary + var control types.EnabledControlSummary resourceName := "aws_controltower_control.test" controlName := "AWS-GR_EC2_VOLUME_INUSE_CHECK" ouName := "Security" @@ -71,7 +72,7 @@ func testAccControl_disappears(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckControlDestroy(ctx), Steps: []resource.TestStep{ @@ -87,25 +88,16 @@ func testAccControl_disappears(t *testing.T) { }) } -func testAccCheckControlExists(ctx context.Context, n string, v *controltower.EnabledControlSummary) resource.TestCheckFunc { +func testAccCheckControlExists(ctx context.Context, n string, v *types.EnabledControlSummary) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No ControlTower Control ID is set") - } - - targetIdentifier, controlIdentifier, err := tfcontroltower.ControlParseResourceID(rs.Primary.ID) - - if err != nil { - return err - } - conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerClient(ctx) - output, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + output, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, rs.Primary.Attributes["target_identifier"], rs.Primary.Attributes["control_identifier"]) if err != nil { return err @@ -119,20 +111,14 @@ func testAccCheckControlExists(ctx context.Context, n string, v *controltower.En func testAccCheckControlDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ControlTowerClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_controltower_control" { continue } - targetIdentifier, controlIdentifier, err := tfcontroltower.ControlParseResourceID(rs.Primary.ID) - - if err != nil { - return err - } - - _, err = tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, targetIdentifier, controlIdentifier) + _, err := tfcontroltower.FindEnabledControlByTwoPartKey(ctx, conn, rs.Primary.Attributes["target_identifier"], rs.Primary.Attributes["control_identifier"]) if tfresource.NotFound(err) { continue diff --git a/internal/service/controltower/controls_data_source.go b/internal/service/controltower/controls_data_source.go index 225bbaf93e6..0b2e44a6fe5 100644 --- a/internal/service/controltower/controls_data_source.go +++ b/internal/service/controltower/controls_data_source.go @@ -6,16 +6,18 @@ package controltower import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/controltower" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/controltower" + "github.com/aws/aws-sdk-go-v2/service/controltower/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" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -// @SDKDataSource("aws_controltower_controls") -func DataSourceControls() *schema.Resource { +// @SDKDataSource("aws_controltower_controls", name="Control") +func dataSourceControls() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: DataSourceControlsRead, @@ -35,35 +37,23 @@ func DataSourceControls() *schema.Resource { } func DataSourceControlsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).ControlTowerConn(ctx) + conn := meta.(*conns.AWSClient).ControlTowerClient(ctx) targetIdentifier := d.Get("target_identifier").(string) input := &controltower.ListEnabledControlsInput{ TargetIdentifier: aws.String(targetIdentifier), } - var controls []string - err := conn.ListEnabledControlsPagesWithContext(ctx, input, func(page *controltower.ListEnabledControlsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, control := range page.EnabledControls { - if control == nil { - continue - } - controls = append(controls, aws.StringValue(control.ControlIdentifier)) - } - - return !lastPage - }) + controls, err := findEnabledControls(ctx, conn, input, tfslices.PredicateTrue[*types.EnabledControlSummary]()) if err != nil { - return diag.Errorf("listing ControlTower Controls (%s): %s", targetIdentifier, err) + return diag.Errorf("reading ControlTower Controls (%s): %s", targetIdentifier, err) } d.SetId(targetIdentifier) - d.Set("enabled_controls", controls) + d.Set("enabled_controls", tfslices.ApplyToAll(controls, func(v *types.EnabledControlSummary) string { + return aws.ToString(v.ControlIdentifier) + })) return nil } diff --git a/internal/service/controltower/controls_data_source_test.go b/internal/service/controltower/controls_data_source_test.go index 3c0a7aa8ac2..127f8431f08 100644 --- a/internal/service/controltower/controls_data_source_test.go +++ b/internal/service/controltower/controls_data_source_test.go @@ -9,10 +9,10 @@ import ( "testing" "github.com/aws/aws-sdk-go/service/cloudtrail" - "github.com/aws/aws-sdk-go/service/controltower" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccControlTowerControlsDataSource_basic(t *testing.T) { @@ -26,7 +26,7 @@ func TestAccControlTowerControlsDataSource_basic(t *testing.T) { acctest.PreCheckOrganizationManagementAccount(ctx, t) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, controltower.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.ControlTowerEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/controltower/exports_test.go b/internal/service/controltower/exports_test.go new file mode 100644 index 00000000000..f5a047b800c --- /dev/null +++ b/internal/service/controltower/exports_test.go @@ -0,0 +1,11 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package controltower + +// Exports for use in tests only. +var ( + ResourceControl = resourceControl + + FindEnabledControlByTwoPartKey = findEnabledControlByTwoPartKey +) diff --git a/internal/service/controltower/service_package_gen.go b/internal/service/controltower/service_package_gen.go index 02e9a984e42..f9c58694ff9 100644 --- a/internal/service/controltower/service_package_gen.go +++ b/internal/service/controltower/service_package_gen.go @@ -5,9 +5,8 @@ package controltower import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - controltower_sdkv1 "github.com/aws/aws-sdk-go/service/controltower" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + controltower_sdkv2 "github.com/aws/aws-sdk-go-v2/service/controltower" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -26,8 +25,9 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceControls, + Factory: dataSourceControls, TypeName: "aws_controltower_controls", + Name: "Control", }, } } @@ -35,8 +35,9 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceControl, + Factory: resourceControl, TypeName: "aws_controltower_control", + Name: "Control", }, } } @@ -45,11 +46,15 @@ func (p *servicePackage) ServicePackageName() string { return names.ControlTower } -// 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) (*controltower_sdkv1.ControlTower, 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) (*controltower_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return controltower_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return controltower_sdkv2.NewFromConfig(cfg, func(o *controltower_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/names/names.go b/names/names.go index 81352a1017b..5f90413c379 100644 --- a/names/names.go +++ b/names/names.go @@ -44,6 +44,7 @@ const ( CodeStarNotificationsEndpointID = "codestar-notifications" ComprehendEndpointID = "comprehend" ComputeOptimizerEndpointID = "computeoptimizer" + ControlTowerEndpointID = "controltower" DSEndpointID = "ds" EKSEndpointID = "eks" EMREndpointID = "elasticmapreduce" diff --git a/names/names_data.csv b/names/names_data.csv index 5d42c6ca4d5..7b9593bdf2d 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -98,7 +98,7 @@ connectparticipant,connectparticipant,connectparticipant,connectparticipant,,con voice-id,voiceid,voiceid,voiceid,,voiceid,,,VoiceID,VoiceID,,1,,,aws_voiceid_,,voiceid_,Connect Voice ID,Amazon,,x,,,,, wisdom,wisdom,connectwisdomservice,wisdom,,wisdom,,connectwisdomservice,Wisdom,ConnectWisdomService,,1,,,aws_wisdom_,,wisdom_,Connect Wisdom,Amazon,,x,,,,, ,,,,,,,,,,,,,,,,,Console Mobile Application,AWS,x,,,,,,No SDK support -controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,1,,,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, +controltower,controltower,controltower,controltower,,controltower,,,ControlTower,ControlTower,,,2,,aws_controltower_,,controltower_,Control Tower,AWS,,,,,,, cur,cur,costandusagereportservice,costandusagereportservice,,cur,,costandusagereportservice,CUR,CostandUsageReportService,,1,,,aws_cur_,,cur_,Cost and Usage Report,AWS,,,,,,, ,,,,,,,,,,,,,,,,,Crypto Tools,AWS,x,,,,,,No SDK support ,,,,,,,,,,,,,,,,,Cryptographic Services Overview,AWS,x,,,,,,No SDK support