diff --git a/.changelog/33416.txt b/.changelog/33416.txt new file mode 100644 index 00000000000..71f1faf437d --- /dev/null +++ b/.changelog/33416.txt @@ -0,0 +1,11 @@ +```release-note:enhancement +resource/aws_s3control_multi_region_access_point: Add `details.region.bucket_account_id` argument to support [cross-account Multi-Region Access Points](https://docs.aws.amazon.com/AmazonS3/latest/userguide/multi-region-access-point-buckets.html) +``` + +```release-note:enhancement +resource/aws_s3control_multi_region_access_point: Add `details.region.region` attribute +``` + +```release-note:enhancement +data-source/aws_s3control_multi_region_access_point: Add `details.region.bucket_account_id` attribute +``` \ No newline at end of file diff --git a/internal/service/codestarnotifications/notification_rule.go b/internal/service/codestarnotifications/notification_rule.go index 695c109ced3..c02d4c2d933 100644 --- a/internal/service/codestarnotifications/notification_rule.go +++ b/internal/service/codestarnotifications/notification_rule.go @@ -276,7 +276,7 @@ func cleanupNotificationRuleTargets(ctx context.Context, conn *codestarnotificat TargetAddress: aws.String(target["address"].(string)), } - _, err := tfresource.RetryWhenAWSErrMessageContainsV2(ctx, targetSubscriptionTimeout, func() (interface{}, error) { + _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, targetSubscriptionTimeout, func() (interface{}, error) { return conn.DeleteTarget(ctx, input) }, "ValidationException", notificationRuleErrorSubscribed) diff --git a/internal/service/ec2/vpc_.go b/internal/service/ec2/vpc_.go index 8b0270842c3..e6cb0dd5d46 100644 --- a/internal/service/ec2/vpc_.go +++ b/internal/service/ec2/vpc_.go @@ -214,7 +214,7 @@ func resourceVPCCreate(ctx context.Context, d *schema.ResourceData, meta interfa } // "UnsupportedOperation: The operation AllocateIpamPoolCidr is not supported. Account 123456789012 is not monitored by IPAM ipam-07b079e3392782a55." - outputRaw, err := tfresource.RetryWhenAWSErrMessageContainsV2(ctx, ec2PropagationTimeout, func() (interface{}, error) { + outputRaw, err := tfresource.RetryWhenAWSErrMessageContains(ctx, ec2PropagationTimeout, func() (interface{}, error) { return conn.CreateVpc(ctx, input) }, errCodeUnsupportedOperation, "is not monitored by IPAM") @@ -450,7 +450,7 @@ func resourceVPCDelete(ctx context.Context, d *schema.ResourceData, meta interfa } log.Printf("[INFO] Deleting EC2 VPC: %s", d.Id()) - _, err := tfresource.RetryWhenAWSErrCodeEqualsV2(ctx, vpcDeletedTimeout, func() (interface{}, error) { + _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, vpcDeletedTimeout, func() (interface{}, error) { return conn.DeleteVpc(ctx, input) }, errCodeDependencyViolation) diff --git a/internal/service/s3control/access_point.go b/internal/service/s3control/access_point.go index 35247448ca0..cdcc1d94c14 100644 --- a/internal/service/s3control/access_point.go +++ b/internal/service/s3control/access_point.go @@ -9,10 +9,11 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -156,14 +157,13 @@ func resourceAccessPoint() *schema.Resource { } func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { accountID = v.(string) } name := d.Get("name").(string) - input := &s3control.CreateAccessPointInput{ AccountId: aws.String(accountID), Bucket: aws.String(d.Get("bucket").(string)), @@ -182,20 +182,18 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta input.VpcConfiguration = expandVPCConfiguration(v.([]interface{})[0].(map[string]interface{})) } - output, err := conn.CreateAccessPointWithContext(ctx, input) + output, err := conn.CreateAccessPoint(ctx, input) if err != nil { return diag.Errorf("creating S3 Access Point (%s): %s", name, err) } - resourceID, err := AccessPointCreateResourceID(aws.StringValue(output.AccessPointArn)) - + resourceID, err := AccessPointCreateResourceID(aws.ToString(output.AccessPointArn)) if err != nil { return diag.FromErr(err) } accountID, name, err = AccessPointParseResourceID(resourceID) - if err != nil { return diag.FromErr(err) } @@ -205,7 +203,7 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("policy"); ok && v.(string) != "" && v.(string) != "{}" { policy, err := structure.NormalizeJsonString(v.(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", v.(string), err) + return diag.FromErr(err) } input := &s3control.PutAccessPointPolicyInput{ @@ -214,7 +212,7 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyWithContext(ctx, input) + _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { return diag.Errorf("creating S3 Access Point (%s) policy: %s", d.Id(), err) @@ -225,17 +223,14 @@ func resourceAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta } func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - s3OnOutposts := arn.IsARN(name) - - output, err := FindAccessPointByTwoPartKey(ctx, conn, accountID, name) + output, err := findAccessPointByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Access Point (%s) not found, removing from state", d.Id()) @@ -247,9 +242,10 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i return diag.Errorf("reading S3 Access Point (%s): %s", d.Id(), err) } + s3OnOutposts := arn.IsARN(name) + if s3OnOutposts { accessPointARN, err := arn.Parse(name) - if err != nil { return diag.FromErr(err) } @@ -262,8 +258,8 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i AccountID: accessPointARN.AccountID, Resource: strings.Replace( accessPointARN.Resource, - fmt.Sprintf("accesspoint/%s", aws.StringValue(output.Name)), - fmt.Sprintf("bucket/%s", aws.StringValue(output.Bucket)), + fmt.Sprintf("accesspoint/%s", aws.ToString(output.Name)), + fmt.Sprintf("bucket/%s", aws.ToString(output.Bucket)), 1, ), } @@ -277,7 +273,7 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i Service: "s3", Region: meta.(*conns.AWSClient).Region, AccountID: accountID, - Resource: fmt.Sprintf("accesspoint/%s", aws.StringValue(output.Name)), + Resource: fmt.Sprintf("accesspoint/%s", aws.ToString(output.Name)), } d.Set("arn", accessPointARN.String()) @@ -287,8 +283,8 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("account_id", accountID) d.Set("alias", output.Alias) d.Set("bucket_account_id", output.BucketAccountId) - d.Set("domain_name", meta.(*conns.AWSClient).RegionalHostname(fmt.Sprintf("%s-%s.s3-accesspoint", aws.StringValue(output.Name), accountID))) - d.Set("endpoints", aws.StringValueMap(output.Endpoints)) + d.Set("domain_name", meta.(*conns.AWSClient).RegionalHostname(fmt.Sprintf("%s-%s.s3-accesspoint", aws.ToString(output.Name), accountID))) + d.Set("endpoints", output.Endpoints) d.Set("name", output.Name) d.Set("network_origin", output.NetworkOrigin) if output.PublicAccessBlockConfiguration != nil { @@ -306,7 +302,7 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i d.Set("vpc_configuration", nil) } - policy, status, err := FindAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) + policy, status, err := findAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) if err == nil && policy != "" { if s3OnOutposts { @@ -332,10 +328,9 @@ func resourceAccessPointRead(ctx context.Context, d *schema.ResourceData, meta i } func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -344,7 +339,7 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("policy"); ok && v.(string) != "" && v.(string) != "{}" { policy, err := structure.NormalizeJsonString(v.(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", v.(string), err) + return diag.FromErr(err) } input := &s3control.PutAccessPointPolicyInput{ @@ -353,16 +348,18 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyWithContext(ctx, input) + _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { return diag.Errorf("updating S3 Access Point (%s) policy: %s", d.Id(), err) } } else { - _, err := conn.DeleteAccessPointPolicyWithContext(ctx, &s3control.DeleteAccessPointPolicyInput{ + input := &s3control.DeleteAccessPointPolicyInput{ AccountId: aws.String(accountID), Name: aws.String(name), - }) + } + + _, err := conn.DeleteAccessPointPolicy(ctx, input) if err != nil { return diag.Errorf("deleting S3 Access Point (%s) policy: %s", d.Id(), err) @@ -374,16 +371,15 @@ func resourceAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta } func resourceAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } log.Printf("[DEBUG] Deleting S3 Access Point: %s", d.Id()) - _, err = conn.DeleteAccessPointWithContext(ctx, &s3control.DeleteAccessPointInput{ + _, err = conn.DeleteAccessPoint(ctx, &s3control.DeleteAccessPointInput{ AccountId: aws.String(accountID), Name: aws.String(name), }) @@ -399,13 +395,13 @@ func resourceAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta return nil } -func FindAccessPointByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.GetAccessPointOutput, error) { +func findAccessPointByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*s3control.GetAccessPointOutput, error) { input := &s3control.GetAccessPointInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output, err := conn.GetAccessPointWithContext(ctx, input) + output, err := conn.GetAccessPoint(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { return nil, &retry.NotFoundError{ @@ -468,12 +464,12 @@ func AccessPointParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected account-id%[2]saccess-point-name", id, accessPointResourceIDSeparator) } -func expandVPCConfiguration(tfMap map[string]interface{}) *s3control.VpcConfiguration { +func expandVPCConfiguration(tfMap map[string]interface{}) *types.VpcConfiguration { if tfMap == nil { return nil } - apiObject := &s3control.VpcConfiguration{} + apiObject := &types.VpcConfiguration{} if v, ok := tfMap["vpc_id"].(string); ok { apiObject.VpcId = aws.String(v) @@ -482,7 +478,7 @@ func expandVPCConfiguration(tfMap map[string]interface{}) *s3control.VpcConfigur return apiObject } -func flattenVPCConfiguration(apiObject *s3control.VpcConfiguration) map[string]interface{} { +func flattenVPCConfiguration(apiObject *types.VpcConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -490,7 +486,7 @@ func flattenVPCConfiguration(apiObject *s3control.VpcConfiguration) map[string]i tfMap := map[string]interface{}{} if v := apiObject.VpcId; v != nil { - tfMap["vpc_id"] = aws.StringValue(v) + tfMap["vpc_id"] = aws.ToString(v) } return tfMap diff --git a/internal/service/s3control/access_point_policy.go b/internal/service/s3control/access_point_policy.go index 1ca7c4216f7..855466a40d0 100644 --- a/internal/service/s3control/access_point_policy.go +++ b/internal/service/s3control/access_point_policy.go @@ -7,9 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3control" - "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/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -59,23 +60,21 @@ func resourceAccessPointPolicy() *schema.Resource { } func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) resourceID, err := AccessPointCreateResourceID(d.Get("access_point_arn").(string)) - if err != nil { return diag.FromErr(err) } accountID, name, err := AccessPointParseResourceID(resourceID) - if err != nil { return diag.FromErr(err) } policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) + return diag.FromErr(err) } input := &s3control.PutAccessPointPolicyInput{ @@ -84,7 +83,7 @@ func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyWithContext(ctx, input) + _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { return diag.Errorf("creating S3 Access Point (%s) Policy: %s", resourceID, err) @@ -96,15 +95,14 @@ func resourceAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData } func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - policy, status, err := FindAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) + policy, status, err := findAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Access Point Policy (%s) not found, removing from state", d.Id()) @@ -133,17 +131,16 @@ func resourceAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, } func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) + return diag.FromErr(err) } input := &s3control.PutAccessPointPolicyInput{ @@ -152,7 +149,7 @@ func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyWithContext(ctx, input) + _, err = conn.PutAccessPointPolicy(ctx, input) if err != nil { return diag.Errorf("updating S3 Access Point Policy (%s): %s", d.Id(), err) @@ -162,16 +159,15 @@ func resourceAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData } func resourceAccessPointPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := AccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } log.Printf("[DEBUG] Deleting S3 Access Point Policy: %s", d.Id()) - _, err = conn.DeleteAccessPointPolicyWithContext(ctx, &s3control.DeleteAccessPointPolicyInput{ + _, err = conn.DeleteAccessPointPolicy(ctx, &s3control.DeleteAccessPointPolicyInput{ AccountId: aws.String(accountID), Name: aws.String(name), }) @@ -200,18 +196,18 @@ func resourceAccessPointPolicyImport(ctx context.Context, d *schema.ResourceData return []*schema.ResourceData{d}, nil } -func FindAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (string, *s3control.PolicyStatus, error) { - input1 := &s3control.GetAccessPointPolicyInput{ +func findAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (string, *types.PolicyStatus, error) { + inputGAPP := &s3control.GetAccessPointPolicyInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output1, err := conn.GetAccessPointPolicyWithContext(ctx, input1) + outputGAPP, err := conn.GetAccessPointPolicy(ctx, inputGAPP) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { return "", nil, &retry.NotFoundError{ LastError: err, - LastRequest: input1, + LastRequest: inputGAPP, } } @@ -219,27 +215,27 @@ func FindAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3con return "", nil, err } - if output1 == nil { - return "", nil, tfresource.NewEmptyResultError(input1) + if outputGAPP == nil { + return "", nil, tfresource.NewEmptyResultError(inputGAPP) } - policy := aws.StringValue(output1.Policy) + policy := aws.ToString(outputGAPP.Policy) if policy == "" { - return "", nil, tfresource.NewEmptyResultError(input1) + return "", nil, tfresource.NewEmptyResultError(inputGAPP) } - input2 := &s3control.GetAccessPointPolicyStatusInput{ + inputGAPPS := &s3control.GetAccessPointPolicyStatusInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output2, err := conn.GetAccessPointPolicyStatusWithContext(ctx, input2) + outputGAPPS, err := conn.GetAccessPointPolicyStatus(ctx, inputGAPPS) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { return "", nil, &retry.NotFoundError{ LastError: err, - LastRequest: input2, + LastRequest: inputGAPPS, } } @@ -247,9 +243,9 @@ func FindAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3con return "", nil, err } - if output2 == nil || output2.PolicyStatus == nil { - return "", nil, tfresource.NewEmptyResultError(input2) + if outputGAPPS == nil || outputGAPPS.PolicyStatus == nil { + return "", nil, tfresource.NewEmptyResultError(inputGAPPS) } - return policy, output2.PolicyStatus, nil + return policy, outputGAPPS.PolicyStatus, nil } diff --git a/internal/service/s3control/access_point_policy_test.go b/internal/service/s3control/access_point_policy_test.go index 759286ad019..6f912b144b6 100644 --- a/internal/service/s3control/access_point_policy_test.go +++ b/internal/service/s3control/access_point_policy_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/s3control" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -17,6 +16,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlAccessPointPolicy_basic(t *testing.T) { @@ -26,7 +26,7 @@ func TestAccS3ControlAccessPointPolicy_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -55,7 +55,7 @@ func TestAccS3ControlAccessPointPolicy_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -79,7 +79,7 @@ func TestAccS3ControlAccessPointPolicy_disappears_AccessPoint(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -102,7 +102,7 @@ func TestAccS3ControlAccessPointPolicy_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -145,7 +145,7 @@ func testAccAccessPointPolicyImportStateIdFunc(n string) resource.ImportStateIdF func testAccCheckAccessPointPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_access_point_policy" { @@ -153,7 +153,6 @@ func testAccCheckAccessPointPolicyDestroy(ctx context.Context) resource.TestChec } accountID, name, err := tfs3control.AccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -182,17 +181,12 @@ func testAccCheckAccessPointPolicyExists(ctx context.Context, n string) resource return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Access Point Policy ID is set") - } - accountID, name, err := tfs3control.AccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) _, _, err = tfs3control.FindAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) diff --git a/internal/service/s3control/access_point_test.go b/internal/service/s3control/access_point_test.go index d4f42b8b5cf..3babc72773e 100644 --- a/internal/service/s3control/access_point_test.go +++ b/internal/service/s3control/access_point_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control" awspolicy "github.com/hashicorp/awspolicyequivalence" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlAccessPoint_basic(t *testing.T) { @@ -29,7 +30,7 @@ func TestAccS3ControlAccessPoint_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -75,7 +76,7 @@ func TestAccS3ControlAccessPoint_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -99,7 +100,7 @@ func TestAccS3ControlAccessPoint_Bucket_arn(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -181,7 +182,7 @@ func TestAccS3ControlAccessPoint_policy(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -235,7 +236,7 @@ func TestAccS3ControlAccessPoint_publicAccessBlock(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -276,7 +277,7 @@ func TestAccS3ControlAccessPoint_vpc(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -311,7 +312,7 @@ func TestAccS3ControlAccessPoint_vpc(t *testing.T) { func testAccCheckAccessPointDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3_access_point" { @@ -319,7 +320,6 @@ func testAccCheckAccessPointDestroy(ctx context.Context) resource.TestCheckFunc } accountID, name, err := tfs3control.AccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -348,17 +348,12 @@ func testAccCheckAccessPointExists(ctx context.Context, n string, v *s3control.G return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Access Point ID is set") - } - accountID, name, err := tfs3control.AccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) output, err := tfs3control.FindAccessPointByTwoPartKey(ctx, conn, accountID, name) @@ -379,17 +374,12 @@ func testAccCheckAccessPointHasPolicy(ctx context.Context, n string, fn func() s return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Access Point ID is set") - } - accountID, name, err := tfs3control.AccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) actualPolicyText, _, err := tfs3control.FindAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) diff --git a/internal/service/s3control/account_public_access_block.go b/internal/service/s3control/account_public_access_block.go index 8a2d821ce85..444cf453d1e 100644 --- a/internal/service/s3control/account_public_access_block.go +++ b/internal/service/s3control/account_public_access_block.go @@ -91,7 +91,7 @@ func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.Resou d.SetId(accountID) _, err = tfresource.RetryWhenNotFound(ctx, propagationTimeout, func() (interface{}, error) { - return FindPublicAccessBlockByAccountID(ctx, conn, d.Id()) + return findPublicAccessBlockByAccountID(ctx, conn, d.Id()) }) if err != nil { @@ -104,7 +104,7 @@ func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.Resou func resourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).S3ControlConn(ctx) - output, err := FindPublicAccessBlockByAccountID(ctx, conn, d.Id()) + output, err := findPublicAccessBlockByAccountID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Account Public Access Block (%s) not found, removing from state", d.Id()) @@ -171,7 +171,7 @@ func resourceAccountPublicAccessBlockDelete(ctx context.Context, d *schema.Resou return nil } -func FindPublicAccessBlockByAccountID(ctx context.Context, conn *s3control.S3Control, accountID string) (*s3control.PublicAccessBlockConfiguration, error) { +func findPublicAccessBlockByAccountID(ctx context.Context, conn *s3control.S3Control, accountID string) (*s3control.PublicAccessBlockConfiguration, error) { input := &s3control.GetPublicAccessBlockInput{ AccountId: aws.String(accountID), } @@ -198,7 +198,7 @@ func FindPublicAccessBlockByAccountID(ctx context.Context, conn *s3control.S3Con func statusPublicAccessBlockEqual(ctx context.Context, conn *s3control.S3Control, accountID string, target *s3control.PublicAccessBlockConfiguration) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindPublicAccessBlockByAccountID(ctx, conn, accountID) + output, err := findPublicAccessBlockByAccountID(ctx, conn, accountID) if tfresource.NotFound(err) { return nil, "", nil diff --git a/internal/service/s3control/account_public_access_block_data_source.go b/internal/service/s3control/account_public_access_block_data_source.go index e3fb50f5f71..693bacecb75 100644 --- a/internal/service/s3control/account_public_access_block_data_source.go +++ b/internal/service/s3control/account_public_access_block_data_source.go @@ -51,7 +51,7 @@ func dataSourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resou accountID = v.(string) } - output, err := FindPublicAccessBlockByAccountID(ctx, conn, accountID) + output, err := findPublicAccessBlockByAccountID(ctx, conn, accountID) if err != nil { return diag.Errorf("reading S3 Account Public Access Block (%s): %s", accountID, err) diff --git a/internal/service/s3control/account_public_access_block_data_source_test.go b/internal/service/s3control/account_public_access_block_data_source_test.go index a2c321dc81a..72ce7a5639f 100644 --- a/internal/service/s3control/account_public_access_block_data_source_test.go +++ b/internal/service/s3control/account_public_access_block_data_source_test.go @@ -6,9 +6,9 @@ package s3control_test import ( "testing" - "github.com/aws/aws-sdk-go/service/s3control" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func testAccAccountPublicAccessBlockDataSource_basic(t *testing.T) { @@ -18,7 +18,7 @@ func testAccAccountPublicAccessBlockDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/s3control/account_public_access_block_test.go b/internal/service/s3control/account_public_access_block_test.go index 7790d24fbb5..845d660020e 100644 --- a/internal/service/s3control/account_public_access_block_test.go +++ b/internal/service/s3control/account_public_access_block_test.go @@ -291,10 +291,6 @@ func testAccCheckAccountPublicAccessBlockExists(ctx context.Context, n string, v return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Account Public Access Block ID is set") - } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) output, err := tfs3control.FindPublicAccessBlockByAccountID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/s3control/bucket.go b/internal/service/s3control/bucket.go index 40db6f4178b..a4d4a5267b7 100644 --- a/internal/service/s3control/bucket.go +++ b/internal/service/s3control/bucket.go @@ -11,10 +11,11 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -83,7 +84,7 @@ func resourceBucket() *schema.Resource { } func resourceBucketCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get("bucket").(string) input := &s3control.CreateBucketInput{ @@ -91,13 +92,13 @@ func resourceBucketCreate(ctx context.Context, d *schema.ResourceData, meta inte OutpostId: aws.String(d.Get("outpost_id").(string)), } - output, err := conn.CreateBucketWithContext(ctx, input) + output, err := conn.CreateBucket(ctx, input) if err != nil { return diag.Errorf("creating S3 Control Bucket (%s): %s", bucket, err) } - d.SetId(aws.StringValue(output.BucketArn)) + d.SetId(aws.ToString(output.BucketArn)) if tags := KeyValueTags(ctx, getTagsIn(ctx)); len(tags) > 0 { if err := bucketUpdateTags(ctx, conn, d.Id(), nil, tags); err != nil { @@ -109,7 +110,7 @@ func resourceBucketCreate(ctx context.Context, d *schema.ResourceData, meta inte } func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -124,7 +125,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } - output, err := FindBucketByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) + output, err := findBucketByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket (%s) not found, removing from state", d.Id()) @@ -139,7 +140,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("arn", d.Id()) d.Set("bucket", output.Bucket) if output.CreationDate != nil { - d.Set("creation_date", aws.TimeValue(output.CreationDate).Format(time.RFC3339)) + d.Set("creation_date", aws.ToTime(output.CreationDate).Format(time.RFC3339)) } d.Set("outpost_id", arnResourceParts[1]) d.Set("public_access_block_enabled", output.PublicAccessBlockEnabled) @@ -156,7 +157,7 @@ func resourceBucketRead(ctx context.Context, d *schema.ResourceData, meta interf } func resourceBucketUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) if d.HasChange("tags_all") { o, n := d.GetChange("tags_all") @@ -170,7 +171,7 @@ func resourceBucketUpdate(ctx context.Context, d *schema.ResourceData, meta inte } func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -188,7 +189,7 @@ func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta inte // InvalidBucketState: Bucket is in an invalid state log.Printf("[DEBUG] Deleting S3 Control Bucket: %s", d.Id()) _, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, bucketStatePropagationTimeout, func() (interface{}, error) { - return conn.DeleteBucketWithContext(ctx, input) + return conn.DeleteBucket(ctx, input) }, errCodeInvalidBucketState) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchOutpost) { @@ -202,13 +203,13 @@ func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta inte return nil } -func FindBucketByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID, bucket string) (*s3control.GetBucketOutput, error) { +func findBucketByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketOutput, error) { input := &s3control.GetBucketInput{ AccountId: aws.String(accountID), Bucket: aws.String(bucket), } - output, err := conn.GetBucketWithContext(ctx, input) + output, err := conn.GetBucket(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchOutpost) { return nil, &retry.NotFoundError{ @@ -232,7 +233,7 @@ func FindBucketByTwoPartKey(ctx context.Context, conn *s3control.S3Control, acco // bucketListTags lists S3control bucket tags. // The identifier is the bucket ARN. -func bucketListTags(ctx context.Context, conn *s3control.S3Control, identifier string) (tftags.KeyValueTags, error) { +func bucketListTags(ctx context.Context, conn *s3control.Client, identifier string) (tftags.KeyValueTags, error) { parsedArn, err := arn.Parse(identifier) if err != nil { @@ -244,7 +245,7 @@ func bucketListTags(ctx context.Context, conn *s3control.S3Control, identifier s Bucket: aws.String(identifier), } - output, err := conn.GetBucketTaggingWithContext(ctx, input) + output, err := conn.GetBucketTagging(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchTagSet) { return tftags.New(ctx, nil), nil @@ -259,7 +260,7 @@ func bucketListTags(ctx context.Context, conn *s3control.S3Control, identifier s // bucketUpdateTags updates S3control bucket tags. // The identifier is the bucket ARN. -func bucketUpdateTags(ctx context.Context, conn *s3control.S3Control, identifier string, oldTagsMap, newTagsMap any) error { +func bucketUpdateTags(ctx context.Context, conn *s3control.Client, identifier string, oldTagsMap, newTagsMap any) error { parsedArn, err := arn.Parse(identifier) if err != nil { @@ -282,12 +283,12 @@ func bucketUpdateTags(ctx context.Context, conn *s3control.S3Control, identifier input := &s3control.PutBucketTaggingInput{ AccountId: aws.String(parsedArn.AccountID), Bucket: aws.String(identifier), - Tagging: &s3control.Tagging{ + Tagging: &types.Tagging{ TagSet: Tags(newTags.Merge(ignoredTags)), }, } - _, err := conn.PutBucketTaggingWithContext(ctx, input) + _, err := conn.PutBucketTagging(ctx, input) if err != nil { return fmt.Errorf("setting resource tags (%s): %s", identifier, err) @@ -298,7 +299,7 @@ func bucketUpdateTags(ctx context.Context, conn *s3control.S3Control, identifier Bucket: aws.String(identifier), } - _, err := conn.DeleteBucketTaggingWithContext(ctx, input) + _, err := conn.DeleteBucketTagging(ctx, input) if err != nil { return fmt.Errorf("deleting resource tags (%s): %s", identifier, err) diff --git a/internal/service/s3control/bucket_lifecycle_configuration.go b/internal/service/s3control/bucket_lifecycle_configuration.go index 126402eed5d..508ebddf3d4 100644 --- a/internal/service/s3control/bucket_lifecycle_configuration.go +++ b/internal/service/s3control/bucket_lifecycle_configuration.go @@ -9,10 +9,11 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -116,7 +117,7 @@ func resourceBucketLifecycleConfiguration() *schema.Resource { "status": { Type: schema.TypeString, Optional: true, - Default: s3control.ExpirationStatusEnabled, + Default: types.ExpirationStatusEnabled, }, }, }, @@ -126,7 +127,7 @@ func resourceBucketLifecycleConfiguration() *schema.Resource { } func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get("bucket").(string) @@ -143,12 +144,12 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R input := &s3control.PutBucketLifecycleConfigurationInput{ AccountId: aws.String(parsedArn.AccountID), Bucket: aws.String(bucket), - LifecycleConfiguration: &s3control.LifecycleConfiguration{ + LifecycleConfiguration: &types.LifecycleConfiguration{ Rules: expandLifecycleRules(ctx, d.Get("rule").(*schema.Set).List()), }, } - _, err = conn.PutBucketLifecycleConfigurationWithContext(ctx, input) + _, err = conn.PutBucketLifecycleConfiguration(ctx, input) if err != nil { return diag.Errorf("creating S3 Control Bucket Lifecycle Configuration (%s): %s", bucket, err) @@ -160,7 +161,7 @@ func resourceBucketLifecycleConfigurationCreate(ctx context.Context, d *schema.R } func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -172,7 +173,7 @@ func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.Res return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } - output, err := FindBucketLifecycleConfigurationByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) + output, err := findBucketLifecycleConfigurationByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket Lifecycle Configuration (%s) not found, removing from state", d.Id()) @@ -194,7 +195,7 @@ func resourceBucketLifecycleConfigurationRead(ctx context.Context, d *schema.Res } func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -209,12 +210,12 @@ func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.R input := &s3control.PutBucketLifecycleConfigurationInput{ AccountId: aws.String(parsedArn.AccountID), Bucket: aws.String(d.Id()), - LifecycleConfiguration: &s3control.LifecycleConfiguration{ + LifecycleConfiguration: &types.LifecycleConfiguration{ Rules: expandLifecycleRules(ctx, d.Get("rule").(*schema.Set).List()), }, } - _, err = conn.PutBucketLifecycleConfigurationWithContext(ctx, input) + _, err = conn.PutBucketLifecycleConfiguration(ctx, input) if err != nil { return diag.Errorf("updating S3 Control Bucket Lifecycle Configuration (%s): %s", d.Id(), err) @@ -224,7 +225,7 @@ func resourceBucketLifecycleConfigurationUpdate(ctx context.Context, d *schema.R } func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -237,7 +238,7 @@ func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.R } log.Printf("[DEBUG] Deleting S3 Control Bucket Lifecycle Configuration: %s", d.Id()) - _, err = conn.DeleteBucketLifecycleConfigurationWithContext(ctx, &s3control.DeleteBucketLifecycleConfigurationInput{ + _, err = conn.DeleteBucketLifecycleConfiguration(ctx, &s3control.DeleteBucketLifecycleConfigurationInput{ AccountId: aws.String(parsedArn.AccountID), Bucket: aws.String(d.Id()), }) @@ -253,13 +254,13 @@ func resourceBucketLifecycleConfigurationDelete(ctx context.Context, d *schema.R return nil } -func FindBucketLifecycleConfigurationByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID, bucket string) (*s3control.GetBucketLifecycleConfigurationOutput, error) { +func findBucketLifecycleConfigurationByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketLifecycleConfigurationOutput, error) { input := &s3control.GetBucketLifecycleConfigurationInput{ AccountId: aws.String(accountID), Bucket: aws.String(bucket), } - output, err := conn.GetBucketLifecycleConfigurationWithContext(ctx, input) + output, err := conn.GetBucketLifecycleConfiguration(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchLifecycleConfiguration, errCodeNoSuchOutpost) { return nil, &retry.NotFoundError{ @@ -279,7 +280,7 @@ func FindBucketLifecycleConfigurationByTwoPartKey(ctx context.Context, conn *s3c return output, nil } -func expandAbortIncompleteMultipartUpload(tfList []interface{}) *s3control.AbortIncompleteMultipartUpload { +func expandAbortIncompleteMultipartUpload(tfList []interface{}) *types.AbortIncompleteMultipartUpload { if len(tfList) == 0 || tfList[0] == nil { return nil } @@ -290,16 +291,16 @@ func expandAbortIncompleteMultipartUpload(tfList []interface{}) *s3control.Abort return nil } - apiObject := &s3control.AbortIncompleteMultipartUpload{} + apiObject := &types.AbortIncompleteMultipartUpload{} if v, ok := tfMap["days_after_initiation"].(int); ok && v != 0 { - apiObject.DaysAfterInitiation = aws.Int64(int64(v)) + apiObject.DaysAfterInitiation = int32(v) } return apiObject } -func expandLifecycleExpiration(tfList []interface{}) *s3control.LifecycleExpiration { +func expandLifecycleExpiration(tfList []interface{}) *types.LifecycleExpiration { if len(tfList) == 0 || tfList[0] == nil { return nil } @@ -310,7 +311,7 @@ func expandLifecycleExpiration(tfList []interface{}) *s3control.LifecycleExpirat return nil } - apiObject := &s3control.LifecycleExpiration{} + apiObject := &types.LifecycleExpiration{} if v, ok := tfMap["date"].(string); ok && v != "" { parsedDate, err := time.Parse("2006-01-02", v) @@ -321,18 +322,18 @@ func expandLifecycleExpiration(tfList []interface{}) *s3control.LifecycleExpirat } if v, ok := tfMap["days"].(int); ok && v != 0 { - apiObject.Days = aws.Int64(int64(v)) + apiObject.Days = int32(v) } if v, ok := tfMap["expired_object_delete_marker"].(bool); ok && v { - apiObject.ExpiredObjectDeleteMarker = aws.Bool(v) + apiObject.ExpiredObjectDeleteMarker = v } return apiObject } -func expandLifecycleRules(ctx context.Context, tfList []interface{}) []*s3control.LifecycleRule { - var apiObjects []*s3control.LifecycleRule +func expandLifecycleRules(ctx context.Context, tfList []interface{}) []types.LifecycleRule { + var apiObjects []types.LifecycleRule for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -347,18 +348,18 @@ func expandLifecycleRules(ctx context.Context, tfList []interface{}) []*s3contro continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func expandLifecycleRule(ctx context.Context, tfMap map[string]interface{}) *s3control.LifecycleRule { +func expandLifecycleRule(ctx context.Context, tfMap map[string]interface{}) *types.LifecycleRule { if len(tfMap) == 0 { return nil } - apiObject := &s3control.LifecycleRule{} + apiObject := &types.LifecycleRule{} if v, ok := tfMap["abort_incomplete_multipart_upload"].([]interface{}); ok && len(v) > 0 { apiObject.AbortIncompleteMultipartUpload = expandAbortIncompleteMultipartUpload(v) @@ -377,21 +378,21 @@ func expandLifecycleRule(ctx context.Context, tfMap map[string]interface{}) *s3c } if v, ok := tfMap["status"].(string); ok && v != "" { - apiObject.Status = aws.String(v) + apiObject.Status = types.ExpirationStatus(v) } // Terraform Plugin SDK sometimes sends map with only empty configuration blocks: // map[abort_incomplete_multipart_upload:[] expiration:[] filter:[] id: status:] // This is to prevent this error: InvalidParameter: 1 validation error(s) found. // - missing required field, PutBucketLifecycleConfigurationInput.LifecycleConfiguration.Rules[0].Status. - if apiObject.ID == nil && apiObject.Status == nil { + if apiObject.ID == nil && apiObject.Status == "" { return nil } return apiObject } -func expandLifecycleRuleFilter(ctx context.Context, tfList []interface{}) *s3control.LifecycleRuleFilter { +func expandLifecycleRuleFilter(ctx context.Context, tfList []interface{}) *types.LifecycleRuleFilter { if len(tfList) == 0 || tfList[0] == nil { return nil } @@ -402,7 +403,7 @@ func expandLifecycleRuleFilter(ctx context.Context, tfList []interface{}) *s3con return nil } - apiObject := &s3control.LifecycleRuleFilter{} + apiObject := &types.LifecycleRuleFilter{} if v, ok := tfMap["prefix"].(string); ok && v != "" { apiObject.Prefix = aws.String(v) @@ -411,9 +412,9 @@ func expandLifecycleRuleFilter(ctx context.Context, tfList []interface{}) *s3con if v, ok := tfMap["tags"].(map[string]interface{}); ok && len(v) > 0 { // See also aws_s3_bucket ReplicationRule.Filter handling if len(v) == 1 { - apiObject.Tag = Tags(tftags.New(ctx, v))[0] + apiObject.Tag = &Tags(tftags.New(ctx, v))[0] } else { - apiObject.And = &s3control.LifecycleRuleAndOperator{ + apiObject.And = &types.LifecycleRuleAndOperator{ Prefix: apiObject.Prefix, Tags: Tags(tftags.New(ctx, v)), } @@ -424,63 +425,50 @@ func expandLifecycleRuleFilter(ctx context.Context, tfList []interface{}) *s3con return apiObject } -func flattenAbortIncompleteMultipartUpload(apiObject *s3control.AbortIncompleteMultipartUpload) []interface{} { +func flattenAbortIncompleteMultipartUpload(apiObject *types.AbortIncompleteMultipartUpload) []interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.DaysAfterInitiation; v != nil { - tfMap["days_after_initiation"] = aws.Int64Value(v) + tfMap := map[string]interface{}{ + "days_after_initiation": apiObject.DaysAfterInitiation, } return []interface{}{tfMap} } -func flattenLifecycleExpiration(apiObject *s3control.LifecycleExpiration) []interface{} { +func flattenLifecycleExpiration(apiObject *types.LifecycleExpiration) []interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.Date; v != nil { - tfMap["date"] = aws.TimeValue(v).Format("2006-01-02") + tfMap := map[string]interface{}{ + "days": apiObject.Days, + "expired_object_delete_marker": apiObject.ExpiredObjectDeleteMarker, } - if v := apiObject.Days; v != nil { - tfMap["days"] = aws.Int64Value(v) - } - - if v := apiObject.ExpiredObjectDeleteMarker; v != nil { - tfMap["expired_object_delete_marker"] = aws.BoolValue(v) + if v := apiObject.Date; v != nil { + tfMap["date"] = aws.ToTime(v).Format("2006-01-02") } return []interface{}{tfMap} } -func flattenLifecycleRules(ctx context.Context, apiObjects []*s3control.LifecycleRule) []interface{} { +func flattenLifecycleRules(ctx context.Context, apiObjects []types.LifecycleRule) []interface{} { var tfMaps []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - tfMaps = append(tfMaps, flattenLifecycleRule(ctx, apiObject)) } return tfMaps } -func flattenLifecycleRule(ctx context.Context, apiObject *s3control.LifecycleRule) map[string]interface{} { - if apiObject == nil { - return nil +func flattenLifecycleRule(ctx context.Context, apiObject types.LifecycleRule) map[string]interface{} { + tfMap := map[string]interface{}{ + "status": apiObject.Status, } - tfMap := map[string]interface{}{} - if v := apiObject.AbortIncompleteMultipartUpload; v != nil { tfMap["abort_incomplete_multipart_upload"] = flattenAbortIncompleteMultipartUpload(v) } @@ -494,17 +482,13 @@ func flattenLifecycleRule(ctx context.Context, apiObject *s3control.LifecycleRul } if v := apiObject.ID; v != nil { - tfMap["id"] = aws.StringValue(v) - } - - if v := apiObject.Status; v != nil { - tfMap["status"] = aws.StringValue(v) + tfMap["id"] = aws.ToString(v) } return tfMap } -func flattenLifecycleRuleFilter(ctx context.Context, apiObject *s3control.LifecycleRuleFilter) []interface{} { +func flattenLifecycleRuleFilter(ctx context.Context, apiObject *types.LifecycleRuleFilter) []interface{} { if apiObject == nil { return nil } @@ -513,7 +497,7 @@ func flattenLifecycleRuleFilter(ctx context.Context, apiObject *s3control.Lifecy if apiObject.And != nil { if v := apiObject.And.Prefix; v != nil { - tfMap["prefix"] = aws.StringValue(v) + tfMap["prefix"] = aws.ToString(v) } if v := apiObject.And.Tags; v != nil { @@ -521,11 +505,11 @@ func flattenLifecycleRuleFilter(ctx context.Context, apiObject *s3control.Lifecy } } else { if v := apiObject.Prefix; v != nil { - tfMap["prefix"] = aws.StringValue(v) + tfMap["prefix"] = aws.ToString(v) } if v := apiObject.Tag; v != nil { - tfMap["tags"] = KeyValueTags(ctx, []*s3control.S3Tag{v}).IgnoreAWS().Map() + tfMap["tags"] = KeyValueTags(ctx, []types.S3Tag{*v}).IgnoreAWS().Map() } } diff --git a/internal/service/s3control/bucket_lifecycle_configuration_test.go b/internal/service/s3control/bucket_lifecycle_configuration_test.go index b8e44bc6503..41b6ff1291c 100644 --- a/internal/service/s3control/bucket_lifecycle_configuration_test.go +++ b/internal/service/s3control/bucket_lifecycle_configuration_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control/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" @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlBucketLifecycleConfiguration_basic(t *testing.T) { @@ -27,7 +28,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -41,7 +42,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_basic(t *testing.T) { "expiration.#": "1", "expiration.0.days": "365", "id": "test", - "status": s3control.ExpirationStatusEnabled, + "status": string(types.ExpirationStatusEnabled), }), ), }, @@ -61,7 +62,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -84,7 +85,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleAbortIncompleteMultipartUp resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -128,7 +129,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleExpiration_date(t *testing resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -170,7 +171,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleExpiration_days(t *testing resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -213,7 +214,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleExpiration_expiredObjectDe resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -255,7 +256,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleFilter_prefix(t *testing.T resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -297,7 +298,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_RuleFilter_tags(t *testing.T) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -357,7 +358,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_Rule_id(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -397,17 +398,17 @@ func TestAccS3ControlBucketLifecycleConfiguration_Rule_status(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketLifecycleConfigurationDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccBucketLifecycleConfigurationConfig_ruleStatus(rName, s3control.ExpirationStatusDisabled), + Config: testAccBucketLifecycleConfigurationConfig_ruleStatus(rName, string(types.ExpirationStatusDisabled)), Check: resource.ComposeTestCheckFunc( testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule.*", map[string]string{ - "status": s3control.ExpirationStatusDisabled, + "status": string(types.ExpirationStatusDisabled), }), ), }, @@ -417,12 +418,12 @@ func TestAccS3ControlBucketLifecycleConfiguration_Rule_status(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccBucketLifecycleConfigurationConfig_ruleStatus(rName, s3control.ExpirationStatusEnabled), + Config: testAccBucketLifecycleConfigurationConfig_ruleStatus(rName, string(types.ExpirationStatusEnabled)), Check: resource.ComposeTestCheckFunc( testAccCheckBucketLifecycleConfigurationExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule.*", map[string]string{ - "status": s3control.ExpirationStatusEnabled, + "status": string(types.ExpirationStatusEnabled), }), ), }, @@ -432,7 +433,7 @@ func TestAccS3ControlBucketLifecycleConfiguration_Rule_status(t *testing.T) { func testAccCheckBucketLifecycleConfigurationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_bucket_lifecycle_configuration" { @@ -440,7 +441,6 @@ func testAccCheckBucketLifecycleConfigurationDestroy(ctx context.Context) resour } parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } @@ -469,14 +469,9 @@ func testAccCheckBucketLifecycleConfigurationExists(ctx context.Context, n strin return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Control Bucket Lifecycle Configuration ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/s3control/bucket_policy.go b/internal/service/s3control/bucket_policy.go index 80862e5ab58..5b267367292 100644 --- a/internal/service/s3control/bucket_policy.go +++ b/internal/service/s3control/bucket_policy.go @@ -7,10 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -56,13 +56,13 @@ func resourceBucketPolicy() *schema.Resource { } func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) bucket := d.Get("bucket").(string) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) + return diag.FromErr(err) } input := &s3control.PutBucketPolicyInput{ @@ -70,7 +70,7 @@ func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, met Policy: aws.String(policy), } - _, err = conn.PutBucketPolicyWithContext(ctx, input) + _, err = conn.PutBucketPolicy(ctx, input) if err != nil { return diag.Errorf("creating S3 Control Bucket Policy (%s): %s", bucket, err) @@ -82,10 +82,9 @@ func resourceBucketPolicyCreate(ctx context.Context, d *schema.ResourceData, met } func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -94,7 +93,7 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta return diag.Errorf("parsing S3 Control Bucket ARN (%s): unknown format", d.Id()) } - output, err := FindBucketPolicyByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) + output, err := findBucketPolicyByTwoPartKey(ctx, conn, parsedArn.AccountID, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Control Bucket Policy (%s) not found, removing from state", d.Id()) @@ -109,7 +108,7 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta d.Set("bucket", d.Id()) if output.Policy != nil { - policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), aws.StringValue(output.Policy)) + policyToSet, err := verify.PolicyToSet(d.Get("policy").(string), aws.ToString(output.Policy)) if err != nil { return diag.FromErr(err) } @@ -123,11 +122,11 @@ func resourceBucketPolicyRead(ctx context.Context, d *schema.ResourceData, meta } func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) + return diag.FromErr(err) } input := &s3control.PutBucketPolicyInput{ @@ -135,7 +134,7 @@ func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, met Policy: aws.String(policy), } - _, err = conn.PutBucketPolicyWithContext(ctx, input) + _, err = conn.PutBucketPolicy(ctx, input) if err != nil { return diag.Errorf("updating S3 Control Bucket Policy (%s): %s", d.Id(), err) @@ -145,7 +144,7 @@ func resourceBucketPolicyUpdate(ctx context.Context, d *schema.ResourceData, met } func resourceBucketPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(d.Id()) @@ -154,7 +153,7 @@ func resourceBucketPolicyDelete(ctx context.Context, d *schema.ResourceData, met } log.Printf("[DEBUG] Deleting S3 Control Bucket Policy: %s", d.Id()) - _, err = conn.DeleteBucketPolicyWithContext(ctx, &s3control.DeleteBucketPolicyInput{ + _, err = conn.DeleteBucketPolicy(ctx, &s3control.DeleteBucketPolicyInput{ AccountId: aws.String(parsedArn.AccountID), Bucket: aws.String(d.Id()), }) @@ -170,13 +169,13 @@ func resourceBucketPolicyDelete(ctx context.Context, d *schema.ResourceData, met return nil } -func FindBucketPolicyByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID, bucket string) (*s3control.GetBucketPolicyOutput, error) { +func findBucketPolicyByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, bucket string) (*s3control.GetBucketPolicyOutput, error) { input := &s3control.GetBucketPolicyInput{ AccountId: aws.String(accountID), Bucket: aws.String(bucket), } - output, err := conn.GetBucketPolicyWithContext(ctx, input) + output, err := conn.GetBucketPolicy(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchBucket, errCodeNoSuchBucketPolicy, errCodeNoSuchOutpost) { return nil, &retry.NotFoundError{ diff --git a/internal/service/s3control/bucket_policy_test.go b/internal/service/s3control/bucket_policy_test.go index 6c4ac389783..37725abd1ff 100644 --- a/internal/service/s3control/bucket_policy_test.go +++ b/internal/service/s3control/bucket_policy_test.go @@ -9,8 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws/arn" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -18,6 +17,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlBucketPolicy_basic(t *testing.T) { @@ -27,7 +27,7 @@ func TestAccS3ControlBucketPolicy_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -55,7 +55,7 @@ func TestAccS3ControlBucketPolicy_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -78,7 +78,7 @@ func TestAccS3ControlBucketPolicy_policy(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -107,7 +107,7 @@ func TestAccS3ControlBucketPolicy_policy(t *testing.T) { func testAccCheckBucketPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_bucket_policy" { @@ -115,7 +115,6 @@ func testAccCheckBucketPolicyDestroy(ctx context.Context) resource.TestCheckFunc } parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } @@ -144,14 +143,9 @@ func testAccCheckBucketPolicyExists(ctx context.Context, n string) resource.Test return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Control Bucket Policy ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/s3control/bucket_test.go b/internal/service/s3control/bucket_test.go index de417774a7f..338d1d3114c 100644 --- a/internal/service/s3control/bucket_test.go +++ b/internal/service/s3control/bucket_test.go @@ -9,8 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws/arn" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -18,6 +17,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlBucket_basic(t *testing.T) { @@ -27,7 +27,7 @@ func TestAccS3ControlBucket_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketDestroy(ctx), Steps: []resource.TestStep{ @@ -59,7 +59,7 @@ func TestAccS3ControlBucket_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketDestroy(ctx), Steps: []resource.TestStep{ @@ -84,7 +84,7 @@ func TestAccS3ControlBucket_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBucketDestroy(ctx), Steps: []resource.TestStep{ @@ -124,7 +124,7 @@ func TestAccS3ControlBucket_tags(t *testing.T) { func testAccCheckBucketDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_bucket" { @@ -132,7 +132,6 @@ func testAccCheckBucketDestroy(ctx context.Context) resource.TestCheckFunc { } parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } @@ -161,14 +160,9 @@ func testAccCheckBucketExists(ctx context.Context, n string) resource.TestCheckF return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Control Bucket ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) parsedArn, err := arn.Parse(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/s3control/consts.go b/internal/service/s3control/consts.go deleted file mode 100644 index 5d170c1a664..00000000000 --- a/internal/service/s3control/consts.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package s3control - -// AsyncOperation.RequestStatus values. -const ( - RequestStatusFailed = "FAILED" - RequestStatusSucceeded = "SUCCEEDED" -) diff --git a/internal/service/s3control/exports_test.go b/internal/service/s3control/exports_test.go index f853f23ed2c..9cb98471b08 100644 --- a/internal/service/s3control/exports_test.go +++ b/internal/service/s3control/exports_test.go @@ -16,4 +16,17 @@ var ( ResourceObjectLambdaAccessPoint = resourceObjectLambdaAccessPoint ResourceObjectLambdaAccessPointPolicy = resourceObjectLambdaAccessPointPolicy ResourceStorageLensConfiguration = resourceStorageLensConfiguration + + FindAccessPointByTwoPartKey = findAccessPointByTwoPartKey + FindAccessPointPolicyAndStatusByTwoPartKey = findAccessPointPolicyAndStatusByTwoPartKey + FindBucketByTwoPartKey = findBucketByTwoPartKey + FindBucketLifecycleConfigurationByTwoPartKey = findBucketLifecycleConfigurationByTwoPartKey + FindBucketPolicyByTwoPartKey = findBucketPolicyByTwoPartKey + FindMultiRegionAccessPointByTwoPartKey = findMultiRegionAccessPointByTwoPartKey + FindMultiRegionAccessPointPolicyDocumentByTwoPartKey = findMultiRegionAccessPointPolicyDocumentByTwoPartKey + FindObjectLambdaAccessPointAliasByTwoPartKey = findObjectLambdaAccessPointAliasByTwoPartKey + FindObjectLambdaAccessPointConfigurationByTwoPartKey = findObjectLambdaAccessPointConfigurationByTwoPartKey + FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey = findObjectLambdaAccessPointPolicyAndStatusByTwoPartKey + FindPublicAccessBlockByAccountID = findPublicAccessBlockByAccountID + FindStorageLensConfigurationByAccountIDAndConfigID = findStorageLensConfigurationByAccountIDAndConfigID ) diff --git a/internal/service/s3control/generate.go b/internal/service/s3control/generate.go index 4a1d30a22d0..336712b75e0 100644 --- a/internal/service/s3control/generate.go +++ b/internal/service/s3control/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ServiceTagsSlice -TagType=S3Tag +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ServiceTagsSlice -SkipAWSServiceImp -TagType=S3Tag //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/s3control/multi_region_access_point.go b/internal/service/s3control/multi_region_access_point.go index 574215a920d..946a95e5e46 100644 --- a/internal/service/s3control/multi_region_access_point.go +++ b/internal/service/s3control/multi_region_access_point.go @@ -10,11 +10,11 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) // @SDKResource("aws_s3control_multi_region_access_point") @@ -120,6 +121,17 @@ func resourceMultiRegionAccessPoint() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringLenBetween(3, 255), }, + "bucket_account_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: verify.ValidAccountID, + }, + "region": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -139,17 +151,12 @@ func resourceMultiRegionAccessPoint() *schema.Resource { } func resourceMultiRegionAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { accountID = v.(string) } - input := &s3control.CreateMultiRegionAccessPointInput{ AccountId: aws.String(accountID), } @@ -158,39 +165,35 @@ func resourceMultiRegionAccessPointCreate(ctx context.Context, d *schema.Resourc input.Details = expandCreateMultiRegionAccessPointInput_(v.([]interface{})[0].(map[string]interface{})) } - resourceID := MultiRegionAccessPointCreateResourceID(accountID, aws.StringValue(input.Details.Name)) + id := MultiRegionAccessPointCreateResourceID(accountID, aws.ToString(input.Details.Name)) - output, err := conn.CreateMultiRegionAccessPointWithContext(ctx, input) + output, err := conn.CreateMultiRegionAccessPoint(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if err != nil { - return diag.Errorf("creating S3 Multi-Region Access Point (%s): %s", resourceID, err) + return diag.Errorf("creating S3 Multi-Region Access Point (%s): %s", id, err) } - d.SetId(resourceID) + d.SetId(id) - _, err = waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.StringValue(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)) - - if err != nil { - return diag.Errorf("waiting for Multi-Region Access Point (%s) create: %s", d.Id(), err) + if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("waiting for S3 Multi-Region Access Point (%s) create: %s", d.Id(), err) } return resourceMultiRegionAccessPointRead(ctx, d, meta) } func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - accessPoint, err := FindMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) + accessPoint, err := findMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Multi-Region Access Point (%s) not found, removing from state", d.Id()) @@ -202,7 +205,7 @@ func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceD return diag.Errorf("reading S3 Multi-Region Access Point (%s): %s", d.Id(), err) } - alias := aws.StringValue(accessPoint.Alias) + alias := aws.ToString(accessPoint.Alias) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, Service: "s3", @@ -223,24 +226,24 @@ func resourceMultiRegionAccessPointRead(ctx context.Context, d *schema.ResourceD } func resourceMultiRegionAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - log.Printf("[DEBUG] Deleting S3 Multi-Region Access Point: %s", d.Id()) - output, err := conn.DeleteMultiRegionAccessPointWithContext(ctx, &s3control.DeleteMultiRegionAccessPointInput{ + input := &s3control.DeleteMultiRegionAccessPointInput{ AccountId: aws.String(accountID), - Details: &s3control.DeleteMultiRegionAccessPointInput_{ + Details: &types.DeleteMultiRegionAccessPointInput{ Name: aws.String(name), }, + } + + log.Printf("[DEBUG] Deleting S3 Multi-Region Access Point: %s", d.Id()) + output, err := conn.DeleteMultiRegionAccessPoint(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchMultiRegionAccessPoint) { @@ -251,40 +254,23 @@ func resourceMultiRegionAccessPointDelete(ctx context.Context, d *schema.Resourc return diag.Errorf("deleting S3 Multi-Region Access Point (%s): %s", d.Id(), err) } - _, err = waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.StringValue(output.RequestTokenARN), d.Timeout(schema.TimeoutDelete)) - - if err != nil { + if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutDelete)); err != nil { return diag.Errorf("waiting for S3 Multi-Region Access Point (%s) delete: %s", d.Id(), err) } return nil } -func ConnForMRAP(ctx context.Context, client *conns.AWSClient) (*s3control.S3Control, error) { - originalConn := client.S3ControlConn(ctx) - // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. - region := endpoints.UsWest2RegionID - - if originalConn.Config.Region != nil && aws.StringValue(originalConn.Config.Region) == region { - return originalConn, nil - } - - sess, err := conns.NewSessionForRegion(&originalConn.Config, region, client.TerraformVersion) - - if err != nil { - return nil, fmt.Errorf("creating AWS session: %w", err) - } - - return s3control.New(sess), nil -} - -func FindMultiRegionAccessPointByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.MultiRegionAccessPointReport, error) { +func findMultiRegionAccessPointByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.MultiRegionAccessPointReport, error) { input := &s3control.GetMultiRegionAccessPointInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output, err := conn.GetMultiRegionAccessPointWithContext(ctx, input) + output, err := conn.GetMultiRegionAccessPoint(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchMultiRegionAccessPoint) { return nil, &retry.NotFoundError{ @@ -304,13 +290,16 @@ func FindMultiRegionAccessPointByTwoPartKey(ctx context.Context, conn *s3control return output.AccessPoint, nil } -func findMultiRegionAccessPointOperationByAccountIDAndTokenARN(ctx context.Context, conn *s3control.S3Control, accountID string, requestTokenARN string) (*s3control.AsyncOperation, error) { +func findMultiRegionAccessPointOperationByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, requestTokenARN string) (*types.AsyncOperation, error) { input := &s3control.DescribeMultiRegionAccessPointOperationInput{ AccountId: aws.String(accountID), RequestTokenARN: aws.String(requestTokenARN), } - output, err := conn.DescribeMultiRegionAccessPointOperationWithContext(ctx, input) + output, err := conn.DescribeMultiRegionAccessPointOperation(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAsyncRequest) { return nil, &retry.NotFoundError{ @@ -330,9 +319,9 @@ func findMultiRegionAccessPointOperationByAccountIDAndTokenARN(ctx context.Conte return output.AsyncOperation, nil } -func statusMultiRegionAccessPointRequest(ctx context.Context, conn *s3control.S3Control, accountID string, requestTokenARN string) retry.StateRefreshFunc { +func statusMultiRegionAccessPointRequest(ctx context.Context, conn *s3control.Client, accountID, requestTokenARN string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := findMultiRegionAccessPointOperationByAccountIDAndTokenARN(ctx, conn, accountID, requestTokenARN) + output, err := findMultiRegionAccessPointOperationByTwoPartKey(ctx, conn, accountID, requestTokenARN) if tfresource.NotFound(err) { return nil, "", nil @@ -342,7 +331,7 @@ func statusMultiRegionAccessPointRequest(ctx context.Context, conn *s3control.S3 return nil, "", err } - return output, aws.StringValue(output.RequestStatus), nil + return output, aws.ToString(output.RequestStatus), nil } } @@ -361,20 +350,25 @@ const ( multiRegionAccessPointRequestSucceededDelay = 15 * time.Second ) -func waitMultiRegionAccessPointRequestSucceeded(ctx context.Context, conn *s3control.S3Control, accountID string, requestTokenArn string, timeout time.Duration) (*s3control.AsyncOperation, error) { //nolint:unparam +func waitMultiRegionAccessPointRequestSucceeded(ctx context.Context, conn *s3control.Client, accountID, requestTokenARN string, timeout time.Duration) (*types.AsyncOperation, error) { //nolint:unparam + const ( + // AsyncOperation.RequestStatus values. + asyncOperationRequestStatusFailed = "FAILED" + asyncOperationRequestStatusSucceeded = "SUCCEEDED" + ) stateConf := &retry.StateChangeConf{ - Target: []string{RequestStatusSucceeded}, + Target: []string{asyncOperationRequestStatusSucceeded}, Timeout: timeout, - Refresh: statusMultiRegionAccessPointRequest(ctx, conn, accountID, requestTokenArn), + Refresh: statusMultiRegionAccessPointRequest(ctx, conn, accountID, requestTokenARN), MinTimeout: multiRegionAccessPointRequestSucceededMinTimeout, Delay: multiRegionAccessPointRequestSucceededDelay, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*s3control.AsyncOperation); ok { - if status, responseDetails := aws.StringValue(output.RequestStatus), output.ResponseDetails; status == RequestStatusFailed && responseDetails != nil && responseDetails.ErrorDetails != nil { - tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.StringValue(responseDetails.ErrorDetails.Code), aws.StringValue(responseDetails.ErrorDetails.Message))) + if output, ok := outputRaw.(*types.AsyncOperation); ok { + if status, responseDetails := aws.ToString(output.RequestStatus), output.ResponseDetails; status == asyncOperationRequestStatusFailed && responseDetails != nil && responseDetails.ErrorDetails != nil { + tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.ToString(responseDetails.ErrorDetails.Code), aws.ToString(responseDetails.ErrorDetails.Message))) } return output, err @@ -402,14 +396,14 @@ func MultiRegionAccessPointParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected account-id%[2]saccess-point-name", id, multiRegionAccessPointResourceIDSeparator) } -func expandCreateMultiRegionAccessPointInput_(tfMap map[string]interface{}) *s3control.CreateMultiRegionAccessPointInput_ { +func expandCreateMultiRegionAccessPointInput_(tfMap map[string]interface{}) *types.CreateMultiRegionAccessPointInput { if tfMap == nil { return nil } - apiObject := &s3control.CreateMultiRegionAccessPointInput_{} + apiObject := &types.CreateMultiRegionAccessPointInput{} - if v, ok := tfMap["name"].(string); ok { + if v, ok := tfMap["name"].(string); ok && v != "" { apiObject.Name = aws.String(v) } @@ -424,52 +418,56 @@ func expandCreateMultiRegionAccessPointInput_(tfMap map[string]interface{}) *s3c return apiObject } -func expandPublicAccessBlockConfiguration(tfMap map[string]interface{}) *s3control.PublicAccessBlockConfiguration { +func expandPublicAccessBlockConfiguration(tfMap map[string]interface{}) *types.PublicAccessBlockConfiguration { if tfMap == nil { return nil } - apiObject := &s3control.PublicAccessBlockConfiguration{} + apiObject := &types.PublicAccessBlockConfiguration{} if v, ok := tfMap["block_public_acls"].(bool); ok { - apiObject.BlockPublicAcls = aws.Bool(v) + apiObject.BlockPublicAcls = v } if v, ok := tfMap["block_public_policy"].(bool); ok { - apiObject.BlockPublicPolicy = aws.Bool(v) + apiObject.BlockPublicPolicy = v } if v, ok := tfMap["ignore_public_acls"].(bool); ok { - apiObject.IgnorePublicAcls = aws.Bool(v) + apiObject.IgnorePublicAcls = v } if v, ok := tfMap["restrict_public_buckets"].(bool); ok { - apiObject.RestrictPublicBuckets = aws.Bool(v) + apiObject.RestrictPublicBuckets = v } return apiObject } -func expandRegion(tfMap map[string]interface{}) *s3control.Region { +func expandRegion(tfMap map[string]interface{}) *types.Region { if tfMap == nil { return nil } - apiObject := &s3control.Region{} + apiObject := &types.Region{} - if v, ok := tfMap["bucket"].(string); ok { + if v, ok := tfMap["bucket"].(string); ok && v != "" { apiObject.Bucket = aws.String(v) } + if v, ok := tfMap["bucket_account_id"].(string); ok && v != "" { + apiObject.BucketAccountId = aws.String(v) + } + return apiObject } -func expandRegions(tfList []interface{}) []*s3control.Region { +func expandRegions(tfList []interface{}) []types.Region { if len(tfList) == 0 { return nil } - var apiObjects []*s3control.Region + var apiObjects []types.Region for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -484,13 +482,13 @@ func expandRegions(tfList []interface{}) []*s3control.Region { continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func flattenMultiRegionAccessPointReport(apiObject *s3control.MultiRegionAccessPointReport) map[string]interface{} { +func flattenMultiRegionAccessPointReport(apiObject *types.MultiRegionAccessPointReport) map[string]interface{} { if apiObject == nil { return nil } @@ -498,7 +496,7 @@ func flattenMultiRegionAccessPointReport(apiObject *s3control.MultiRegionAccessP tfMap := map[string]interface{}{} if v := apiObject.Name; v != nil { - tfMap["name"] = aws.StringValue(v) + tfMap["name"] = aws.ToString(v) } if v := apiObject.PublicAccessBlock; v != nil { @@ -512,47 +510,40 @@ func flattenMultiRegionAccessPointReport(apiObject *s3control.MultiRegionAccessP return tfMap } -func flattenPublicAccessBlockConfiguration(apiObject *s3control.PublicAccessBlockConfiguration) map[string]interface{} { +func flattenPublicAccessBlockConfiguration(apiObject *types.PublicAccessBlockConfiguration) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.BlockPublicAcls; v != nil { - tfMap["block_public_acls"] = aws.BoolValue(v) - } - - if v := apiObject.BlockPublicPolicy; v != nil { - tfMap["block_public_policy"] = aws.BoolValue(v) - } - - if v := apiObject.IgnorePublicAcls; v != nil { - tfMap["ignore_public_acls"] = aws.BoolValue(v) - } - - if v := apiObject.RestrictPublicBuckets; v != nil { - tfMap["restrict_public_buckets"] = aws.BoolValue(v) + tfMap := map[string]interface{}{ + "block_public_acls": apiObject.BlockPublicAcls, + "block_public_policy": apiObject.BlockPublicPolicy, + "ignore_public_acls": apiObject.IgnorePublicAcls, + "restrict_public_buckets": apiObject.RestrictPublicBuckets, } return tfMap } -func flattenRegionReport(apiObject *s3control.RegionReport) map[string]interface{} { - if apiObject == nil { - return nil - } - +func flattenRegionReport(apiObject types.RegionReport) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.Bucket; v != nil { - tfMap["bucket"] = aws.StringValue(v) + tfMap["bucket"] = aws.ToString(v) + } + + if v := apiObject.BucketAccountId; v != nil { + tfMap["bucket_account_id"] = aws.ToString(v) + } + + if v := apiObject.Region; v != nil { + tfMap["region"] = aws.ToString(v) } return tfMap } -func flattenRegionReports(apiObjects []*s3control.RegionReport) []interface{} { +func flattenRegionReports(apiObjects []types.RegionReport) []interface{} { if len(apiObjects) == 0 { return nil } @@ -560,10 +551,6 @@ func flattenRegionReports(apiObjects []*s3control.RegionReport) []interface{} { var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - tfList = append(tfList, flattenRegionReport(apiObject)) } diff --git a/internal/service/s3control/multi_region_access_point_data_source.go b/internal/service/s3control/multi_region_access_point_data_source.go index 859757c79c5..286960f8c1c 100644 --- a/internal/service/s3control/multi_region_access_point_data_source.go +++ b/internal/service/s3control/multi_region_access_point_data_source.go @@ -8,8 +8,8 @@ import ( "fmt" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" "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" @@ -81,6 +81,10 @@ func dataSourceMultiRegionAccessPoint() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "bucket_account_id": { + Type: schema.TypeString, + Computed: true, + }, "region": { Type: schema.TypeString, Computed: true, @@ -97,11 +101,7 @@ func dataSourceMultiRegionAccessPoint() *schema.Resource { } func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { @@ -109,7 +109,7 @@ func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.Re } name := d.Get("name").(string) - accessPoint, err := FindMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) + accessPoint, err := findMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) if err != nil { return diag.Errorf("reading S3 Multi Region Access Point (%s): %s", name, err) @@ -117,7 +117,7 @@ func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.Re d.SetId(MultiRegionAccessPointCreateResourceID(accountID, name)) - alias := aws.StringValue(accessPoint.Alias) + alias := aws.ToString(accessPoint.Alias) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, Service: "s3", @@ -127,7 +127,7 @@ func dataSourceMultiRegionAccessPointBlockRead(ctx context.Context, d *schema.Re d.Set("account_id", accountID) d.Set("alias", alias) d.Set("arn", arn) - d.Set("created_at", aws.TimeValue(accessPoint.CreatedAt).Format(time.RFC3339)) + d.Set("created_at", aws.ToTime(accessPoint.CreatedAt).Format(time.RFC3339)) // https://docs.aws.amazon.com/AmazonS3/latest/userguide//MultiRegionAccessPointRequests.html#MultiRegionAccessPointHostnames. d.Set("domain_name", meta.(*conns.AWSClient).PartitionHostname(fmt.Sprintf("%s.accesspoint.s3-global", alias))) d.Set("name", accessPoint.Name) diff --git a/internal/service/s3control/multi_region_access_point_data_source_test.go b/internal/service/s3control/multi_region_access_point_data_source_test.go index a971b54b7cd..40e5326ce58 100644 --- a/internal/service/s3control/multi_region_access_point_data_source_test.go +++ b/internal/service/s3control/multi_region_access_point_data_source_test.go @@ -7,11 +7,10 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/s3control" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlMultiRegionAccessPointDataSource_basic(t *testing.T) { @@ -26,9 +25,9 @@ func TestAccS3ControlMultiRegionAccessPointDataSource_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckMultipleRegion(t, 2) - acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5FactoriesMultipleRegions(ctx, t, 2), Steps: []resource.TestStep{ { diff --git a/internal/service/s3control/multi_region_access_point_policy.go b/internal/service/s3control/multi_region_access_point_policy.go index 103c9701679..b90e52e1961 100644 --- a/internal/service/s3control/multi_region_access_point_policy.go +++ b/internal/service/s3control/multi_region_access_point_policy.go @@ -8,9 +8,10 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3control" - "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/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -19,6 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) // @SDKResource("aws_s3control_multi_region_access_point_policy") @@ -86,17 +88,12 @@ func resourceMultiRegionAccessPointPolicy() *schema.Resource { } func resourceMultiRegionAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { accountID = v.(string) } - input := &s3control.PutMultiRegionAccessPointPolicyInput{ AccountId: aws.String(accountID), } @@ -105,19 +102,20 @@ func resourceMultiRegionAccessPointPolicyCreate(ctx context.Context, d *schema.R input.Details = expandPutMultiRegionAccessPointPolicyInput_(v.([]interface{})[0].(map[string]interface{})) } - resourceID := MultiRegionAccessPointCreateResourceID(accountID, aws.StringValue(input.Details.Name)) + id := MultiRegionAccessPointCreateResourceID(accountID, aws.ToString(input.Details.Name)) - output, err := conn.PutMultiRegionAccessPointPolicyWithContext(ctx, input) + output, err := conn.PutMultiRegionAccessPointPolicy(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if err != nil { - return diag.Errorf("creating S3 Multi-Region Access Point (%s) Policy: %s", resourceID, err) + return diag.Errorf("creating S3 Multi-Region Access Point (%s) Policy: %s", id, err) } - d.SetId(resourceID) + d.SetId(id) - _, err = waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.StringValue(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)) - - if err != nil { + if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("waiting for S3 Multi-Region Access Point Policy (%s) create: %s", d.Id(), err) } @@ -125,19 +123,14 @@ func resourceMultiRegionAccessPointPolicyCreate(ctx context.Context, d *schema.R } func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := MultiRegionAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - policyDocument, err := FindMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx, conn, accountID, name) + policyDocument, err := findMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Multi-Region Access Point Policy (%s) not found, removing from state", d.Id()) @@ -177,14 +170,9 @@ func resourceMultiRegionAccessPointPolicyRead(ctx context.Context, d *schema.Res } func resourceMultiRegionAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn, err := ConnForMRAP(ctx, meta.(*conns.AWSClient)) - - if err != nil { - return diag.FromErr(err) - } + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, _, err := MultiRegionAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -197,28 +185,32 @@ func resourceMultiRegionAccessPointPolicyUpdate(ctx context.Context, d *schema.R input.Details = expandPutMultiRegionAccessPointPolicyInput_(v.([]interface{})[0].(map[string]interface{})) } - output, err := conn.PutMultiRegionAccessPointPolicyWithContext(ctx, input) + output, err := conn.PutMultiRegionAccessPointPolicy(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if err != nil { return diag.Errorf("updating S3 Multi-Region Access Point Policy (%s): %s", d.Id(), err) } - _, err = waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.StringValue(output.RequestTokenARN), d.Timeout(schema.TimeoutUpdate)) - - if err != nil { + if _, err := waitMultiRegionAccessPointRequestSucceeded(ctx, conn, accountID, aws.ToString(output.RequestTokenARN), d.Timeout(schema.TimeoutUpdate)); err != nil { return diag.Errorf("waiting for S3 Multi-Region Access Point Policy (%s) update: %s", d.Id(), err) } return resourceMultiRegionAccessPointPolicyRead(ctx, d, meta) } -func FindMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.MultiRegionAccessPointPolicyDocument, error) { +func findMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.MultiRegionAccessPointPolicyDocument, error) { input := &s3control.GetMultiRegionAccessPointPolicyInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output, err := conn.GetMultiRegionAccessPointPolicyWithContext(ctx, input) + output, err := conn.GetMultiRegionAccessPointPolicy(ctx, input, func(o *s3control.Options) { + // All Multi-Region Access Point actions are routed to the US West (Oregon) Region. + o.Region = names.USWest2RegionID + }) if tfawserr.ErrCodeEquals(err, errCodeNoSuchMultiRegionAccessPoint) { return nil, &retry.NotFoundError{ @@ -238,12 +230,12 @@ func FindMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx context.Context, c return output.Policy, nil } -func expandPutMultiRegionAccessPointPolicyInput_(tfMap map[string]interface{}) *s3control.PutMultiRegionAccessPointPolicyInput_ { +func expandPutMultiRegionAccessPointPolicyInput_(tfMap map[string]interface{}) *types.PutMultiRegionAccessPointPolicyInput { if tfMap == nil { return nil } - apiObject := &s3control.PutMultiRegionAccessPointPolicyInput_{} + apiObject := &types.PutMultiRegionAccessPointPolicyInput{} if v, ok := tfMap["name"].(string); ok { apiObject.Name = aws.String(v) @@ -261,7 +253,7 @@ func expandPutMultiRegionAccessPointPolicyInput_(tfMap map[string]interface{}) * return apiObject } -func flattenMultiRegionAccessPointPolicyDocument(name string, apiObject *s3control.MultiRegionAccessPointPolicyDocument, old map[string]interface{}) map[string]interface{} { +func flattenMultiRegionAccessPointPolicyDocument(name string, apiObject *types.MultiRegionAccessPointPolicyDocument, old map[string]interface{}) map[string]interface{} { if apiObject == nil { return nil } @@ -272,14 +264,14 @@ func flattenMultiRegionAccessPointPolicyDocument(name string, apiObject *s3contr if v := apiObject.Proposed; v != nil { if v := v.Policy; v != nil { - policyToSet := aws.StringValue(v) + policyToSet := aws.ToString(v) if old != nil { if w, ok := old["policy"].(string); ok { var err error - policyToSet, err = verify.PolicyToSet(w, aws.StringValue(v)) + policyToSet, err = verify.PolicyToSet(w, aws.ToString(v)) if err != nil { - policyToSet = aws.StringValue(v) + policyToSet = aws.ToString(v) } } } diff --git a/internal/service/s3control/multi_region_access_point_policy_test.go b/internal/service/s3control/multi_region_access_point_policy_test.go index 78e122ce17b..a2cbb100107 100644 --- a/internal/service/s3control/multi_region_access_point_policy_test.go +++ b/internal/service/s3control/multi_region_access_point_policy_test.go @@ -8,27 +8,27 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3control/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlMultiRegionAccessPointPolicy_basic(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointPolicyDocument + var v types.MultiRegionAccessPointPolicyDocument resourceName := "aws_s3control_multi_region_access_point_policy.test" bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) multiRegionAccessPointName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, // Multi-Region Access Point Policy cannot be deleted once applied. // Ensure parent resource is destroyed instead. @@ -58,15 +58,15 @@ func TestAccS3ControlMultiRegionAccessPointPolicy_basic(t *testing.T) { func TestAccS3ControlMultiRegionAccessPointPolicy_disappears_MultiRegionAccessPoint(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointReport + var v types.MultiRegionAccessPointReport parentResourceName := "aws_s3control_multi_region_access_point.test" resourceName := "aws_s3control_multi_region_access_point_policy.test" bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, // Multi-Region Access Point Policy cannot be deleted once applied. // Ensure parent resource is destroyed instead. @@ -86,14 +86,14 @@ func TestAccS3ControlMultiRegionAccessPointPolicy_disappears_MultiRegionAccessPo func TestAccS3ControlMultiRegionAccessPointPolicy_details_policy(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 s3control.MultiRegionAccessPointPolicyDocument + var v1, v2 types.MultiRegionAccessPointPolicyDocument resourceName := "aws_s3control_multi_region_access_point_policy.test" multiRegionAccessPointName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, // Multi-Region Access Point Policy cannot be deleted once applied. // Ensure parent resource is destroyed instead. @@ -123,15 +123,15 @@ func TestAccS3ControlMultiRegionAccessPointPolicy_details_policy(t *testing.T) { func TestAccS3ControlMultiRegionAccessPointPolicy_details_name(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 s3control.MultiRegionAccessPointPolicyDocument + var v1, v2 types.MultiRegionAccessPointPolicyDocument resourceName := "aws_s3control_multi_region_access_point_policy.test" multiRegionAccessPointName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) multiRegionAccessPointName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, // Multi-Region Access Point Policy cannot be deleted once applied. // Ensure parent resource is destroyed instead. @@ -160,28 +160,19 @@ func TestAccS3ControlMultiRegionAccessPointPolicy_details_name(t *testing.T) { }) } -func testAccCheckMultiRegionAccessPointPolicyExists(ctx context.Context, n string, v *s3control.MultiRegionAccessPointPolicyDocument) resource.TestCheckFunc { +func testAccCheckMultiRegionAccessPointPolicyExists(ctx context.Context, n string, v *types.MultiRegionAccessPointPolicyDocument) 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 S3 Multi-Region Access Point Policy ID is set") - } - accountID, name, err := tfs3control.MultiRegionAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn, err := tfs3control.ConnForMRAP(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - - if err != nil { - return err - } + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) output, err := tfs3control.FindMultiRegionAccessPointPolicyDocumentByTwoPartKey(ctx, conn, accountID, name) @@ -195,9 +186,9 @@ func testAccCheckMultiRegionAccessPointPolicyExists(ctx context.Context, n strin } } -func testAccCheckMultiRegionAccessPointPolicyChanged(i, j *s3control.MultiRegionAccessPointPolicyDocument) resource.TestCheckFunc { +func testAccCheckMultiRegionAccessPointPolicyChanged(i, j *types.MultiRegionAccessPointPolicyDocument) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.StringValue(i.Proposed.Policy) == aws.StringValue(j.Proposed.Policy) { + if aws.ToString(i.Proposed.Policy) == aws.ToString(j.Proposed.Policy) { return fmt.Errorf("S3 Multi-Region Access Point Policy did not change") } diff --git a/internal/service/s3control/multi_region_access_point_test.go b/internal/service/s3control/multi_region_access_point_test.go index 4ad1bb78b5c..1e180b9c289 100644 --- a/internal/service/s3control/multi_region_access_point_test.go +++ b/internal/service/s3control/multi_region_access_point_test.go @@ -9,9 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3control/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" @@ -19,18 +18,19 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlMultiRegionAccessPoint_basic(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointReport + var v types.MultiRegionAccessPointReport resourceName := "aws_s3control_multi_region_access_point.test" bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -51,9 +51,11 @@ func TestAccS3ControlMultiRegionAccessPoint_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "details.0.public_access_block.0.restrict_public_buckets", "true"), resource.TestCheckResourceAttr(resourceName, "details.0.region.#", "1"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "details.0.region.*", map[string]string{ - "bucket": bucketName, + "bucket": bucketName, + "bucket_account_id": acctest.AccountID(), + "region": acctest.Region(), }), - resource.TestCheckResourceAttr(resourceName, "status", s3control.MultiRegionAccessPointStatusReady), + resource.TestCheckResourceAttr(resourceName, "status", string(types.MultiRegionAccessPointStatusReady)), ), }, { @@ -67,14 +69,14 @@ func TestAccS3ControlMultiRegionAccessPoint_basic(t *testing.T) { func TestAccS3ControlMultiRegionAccessPoint_disappears(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointReport + var v types.MultiRegionAccessPointReport resourceName := "aws_s3control_multi_region_access_point.test" bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -92,14 +94,14 @@ func TestAccS3ControlMultiRegionAccessPoint_disappears(t *testing.T) { func TestAccS3ControlMultiRegionAccessPoint_PublicAccessBlock(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointReport + var v types.MultiRegionAccessPointReport resourceName := "aws_s3control_multi_region_access_point.test" bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -125,15 +127,15 @@ func TestAccS3ControlMultiRegionAccessPoint_PublicAccessBlock(t *testing.T) { func TestAccS3ControlMultiRegionAccessPoint_name(t *testing.T) { ctx := acctest.Context(t) - var v1, v2 s3control.MultiRegionAccessPointReport + var v1, v2 types.MultiRegionAccessPointReport resourceName := "aws_s3control_multi_region_access_point.test" rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -163,7 +165,7 @@ func TestAccS3ControlMultiRegionAccessPoint_name(t *testing.T) { func TestAccS3ControlMultiRegionAccessPoint_threeRegions(t *testing.T) { ctx := acctest.Context(t) - var v s3control.MultiRegionAccessPointReport + var v types.MultiRegionAccessPointReport resourceName := "aws_s3control_multi_region_access_point.test" bucket1Name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucket2Name := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -174,9 +176,9 @@ func TestAccS3ControlMultiRegionAccessPoint_threeRegions(t *testing.T) { PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckMultipleRegion(t, 3) - acctest.PreCheckPartitionNot(t, endpoints.AwsUsGovPartitionID) + acctest.PreCheckPartitionNot(t, names.USGovCloudPartitionID) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5FactoriesMultipleRegions(ctx, t, 3), CheckDestroy: testAccCheckMultiRegionAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -194,7 +196,7 @@ func TestAccS3ControlMultiRegionAccessPoint_threeRegions(t *testing.T) { resource.TestCheckTypeSetElemNestedAttrs(resourceName, "details.0.region.*", map[string]string{ "bucket": bucket3Name, }), - resource.TestCheckResourceAttr(resourceName, "status", s3control.MultiRegionAccessPointStatusReady), + resource.TestCheckResourceAttr(resourceName, "status", string(types.MultiRegionAccessPointStatusReady)), ), }, { @@ -208,11 +210,7 @@ func TestAccS3ControlMultiRegionAccessPoint_threeRegions(t *testing.T) { func testAccCheckMultiRegionAccessPointDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn, err := tfs3control.ConnForMRAP(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - - if err != nil { - return err - } + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_multi_region_access_point" { @@ -220,7 +218,6 @@ func testAccCheckMultiRegionAccessPointDestroy(ctx context.Context) resource.Tes } accountID, name, err := tfs3control.MultiRegionAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -242,28 +239,19 @@ func testAccCheckMultiRegionAccessPointDestroy(ctx context.Context) resource.Tes } } -func testAccCheckMultiRegionAccessPointExists(ctx context.Context, n string, v *s3control.MultiRegionAccessPointReport) resource.TestCheckFunc { +func testAccCheckMultiRegionAccessPointExists(ctx context.Context, n string, v *types.MultiRegionAccessPointReport) 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 S3 Multi-Region Access Point ID is set") - } - accountID, name, err := tfs3control.MultiRegionAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn, err := tfs3control.ConnForMRAP(ctx, acctest.Provider.Meta().(*conns.AWSClient)) - - if err != nil { - return err - } + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) output, err := tfs3control.FindMultiRegionAccessPointByTwoPartKey(ctx, conn, accountID, name) @@ -280,9 +268,9 @@ func testAccCheckMultiRegionAccessPointExists(ctx context.Context, n string, v * // Multi-Region Access Point aliases are unique throughout time and aren’t based on the name or configuration of a Multi-Region Access Point. // If you create a Multi-Region Access Point, and then delete it and create another one with the same name and configuration, the // second Multi-Region Access Point will have a different alias than the first. (https://docs.aws.amazon.com/AmazonS3/latest/userguide/CreatingMultiRegionAccessPoints.html#multi-region-access-point-naming) -func testAccCheckMultiRegionAccessPointRecreated(before, after *s3control.MultiRegionAccessPointReport) resource.TestCheckFunc { +func testAccCheckMultiRegionAccessPointRecreated(before, after *types.MultiRegionAccessPointReport) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := aws.StringValue(before.Alias), aws.StringValue(after.Alias); before == after { + if before, after := aws.ToString(before.Alias), aws.ToString(after.Alias); before == after { return fmt.Errorf("S3 Multi-Region Access Point (%s) not recreated", before) } diff --git a/internal/service/s3control/object_lambda_access_point.go b/internal/service/s3control/object_lambda_access_point.go index 7c467563bcf..36f3867cad6 100644 --- a/internal/service/s3control/object_lambda_access_point.go +++ b/internal/service/s3control/object_lambda_access_point.go @@ -9,15 +9,16 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/s3control" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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-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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -61,8 +62,8 @@ func resourceObjectLambdaAccessPoint() *schema.Resource { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(s3control.ObjectLambdaAllowedFeature_Values(), false), + Type: schema.TypeString, + ValidateDiagFunc: enum.Validate[types.ObjectLambdaAllowedFeature](), }, }, "cloud_watch_metrics_enabled": { @@ -84,8 +85,8 @@ func resourceObjectLambdaAccessPoint() *schema.Resource { Type: schema.TypeSet, Required: true, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(s3control.ObjectLambdaTransformationConfigurationAction_Values(), false), + Type: schema.TypeString, + ValidateDiagFunc: enum.Validate[types.ObjectLambdaTransformationConfigurationAction](), }, }, "content_transformation": { @@ -131,15 +132,14 @@ func resourceObjectLambdaAccessPoint() *schema.Resource { } func resourceObjectLambdaAccessPointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { accountID = v.(string) } name := d.Get("name").(string) - resourceID := ObjectLambdaAccessPointCreateResourceID(accountID, name) - + id := ObjectLambdaAccessPointCreateResourceID(accountID, name) input := &s3control.CreateAccessPointForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), @@ -149,27 +149,26 @@ func resourceObjectLambdaAccessPointCreate(ctx context.Context, d *schema.Resour input.Configuration = expandObjectLambdaConfiguration(v.([]interface{})[0].(map[string]interface{})) } - _, err := conn.CreateAccessPointForObjectLambdaWithContext(ctx, input) + _, err := conn.CreateAccessPointForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("creating S3 Object Lambda Access Point (%s): %s", resourceID, err) + return diag.Errorf("creating S3 Object Lambda Access Point (%s): %s", id, err) } - d.SetId(resourceID) + d.SetId(id) return resourceObjectLambdaAccessPointRead(ctx, d, meta) } func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - outputConfiguration, err := FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name) + outputConfiguration, err := findObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Object Lambda Access Point (%s) not found, removing from state", d.Id()) @@ -196,7 +195,7 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource } d.Set("name", name) - outputAlias, err := FindObjectLambdaAccessPointAliasByTwoPartKey(ctx, conn, accountID, name) + outputAlias, err := findObjectLambdaAccessPointAliasByTwoPartKey(ctx, conn, accountID, name) if err != nil { return diag.Errorf("reading S3 Object Lambda Access Point (%s): %s", d.Id(), err) @@ -208,10 +207,9 @@ func resourceObjectLambdaAccessPointRead(ctx context.Context, d *schema.Resource } func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -225,7 +223,7 @@ func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.Resour input.Configuration = expandObjectLambdaConfiguration(v.([]interface{})[0].(map[string]interface{})) } - _, err = conn.PutAccessPointConfigurationForObjectLambdaWithContext(ctx, input) + _, err = conn.PutAccessPointConfigurationForObjectLambda(ctx, input) if err != nil { return diag.Errorf("updating S3 Object Lambda Access Point (%s): %s", d.Id(), err) @@ -235,16 +233,15 @@ func resourceObjectLambdaAccessPointUpdate(ctx context.Context, d *schema.Resour } func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } log.Printf("[DEBUG] Deleting S3 Object Lambda Access Point: %s", d.Id()) - _, err = conn.DeleteAccessPointForObjectLambdaWithContext(ctx, &s3control.DeleteAccessPointForObjectLambdaInput{ + _, err = conn.DeleteAccessPointForObjectLambda(ctx, &s3control.DeleteAccessPointForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), }) @@ -260,13 +257,13 @@ func resourceObjectLambdaAccessPointDelete(ctx context.Context, d *schema.Resour return nil } -func FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaConfiguration, error) { +func findObjectLambdaAccessPointConfigurationByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.ObjectLambdaConfiguration, error) { input := &s3control.GetAccessPointConfigurationForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output, err := conn.GetAccessPointConfigurationForObjectLambdaWithContext(ctx, input) + output, err := conn.GetAccessPointConfigurationForObjectLambda(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { return nil, &retry.NotFoundError{ @@ -286,13 +283,13 @@ func FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx context.Context, c return output.Configuration, nil } -func FindObjectLambdaAccessPointAliasByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (*s3control.ObjectLambdaAccessPointAlias, error) { +func findObjectLambdaAccessPointAliasByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (*types.ObjectLambdaAccessPointAlias, error) { input := &s3control.GetAccessPointForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output, err := conn.GetAccessPointForObjectLambdaWithContext(ctx, input) + output, err := conn.GetAccessPointForObjectLambda(ctx, input) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint) { return nil, &retry.NotFoundError{ @@ -331,19 +328,19 @@ func ObjectLambdaAccessPointParseResourceID(id string) (string, string, error) { return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected account-id%[2]saccess-point-name", id, objectLambdaAccessPointResourceIDSeparator) } -func expandObjectLambdaConfiguration(tfMap map[string]interface{}) *s3control.ObjectLambdaConfiguration { +func expandObjectLambdaConfiguration(tfMap map[string]interface{}) *types.ObjectLambdaConfiguration { if tfMap == nil { return nil } - apiObject := &s3control.ObjectLambdaConfiguration{} + apiObject := &types.ObjectLambdaConfiguration{} if v, ok := tfMap["allowed_features"].(*schema.Set); ok && v.Len() > 0 { - apiObject.AllowedFeatures = flex.ExpandStringSet(v) + apiObject.AllowedFeatures = flex.ExpandStringyValueSet[types.ObjectLambdaAllowedFeature](v) } if v, ok := tfMap["cloud_watch_metrics_enabled"].(bool); ok && v { - apiObject.CloudWatchMetricsEnabled = aws.Bool(v) + apiObject.CloudWatchMetricsEnabled = v } if v, ok := tfMap["supporting_access_point"].(string); ok && v != "" { @@ -357,15 +354,15 @@ func expandObjectLambdaConfiguration(tfMap map[string]interface{}) *s3control.Ob return apiObject } -func expandObjectLambdaTransformationConfiguration(tfMap map[string]interface{}) *s3control.ObjectLambdaTransformationConfiguration { +func expandObjectLambdaTransformationConfiguration(tfMap map[string]interface{}) *types.ObjectLambdaTransformationConfiguration { if tfMap == nil { return nil } - apiObject := &s3control.ObjectLambdaTransformationConfiguration{} + apiObject := &types.ObjectLambdaTransformationConfiguration{} if v, ok := tfMap["actions"].(*schema.Set); ok && v.Len() > 0 { - apiObject.Actions = flex.ExpandStringSet(v) + apiObject.Actions = flex.ExpandStringyValueSet[types.ObjectLambdaTransformationConfigurationAction](v) } if v, ok := tfMap["content_transformation"].([]interface{}); ok && len(v) > 0 { @@ -375,12 +372,12 @@ func expandObjectLambdaTransformationConfiguration(tfMap map[string]interface{}) return apiObject } -func expandObjectLambdaTransformationConfigurations(tfList []interface{}) []*s3control.ObjectLambdaTransformationConfiguration { +func expandObjectLambdaTransformationConfigurations(tfList []interface{}) []types.ObjectLambdaTransformationConfiguration { if len(tfList) == 0 { return nil } - var apiObjects []*s3control.ObjectLambdaTransformationConfiguration + var apiObjects []types.ObjectLambdaTransformationConfiguration for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -395,32 +392,28 @@ func expandObjectLambdaTransformationConfigurations(tfList []interface{}) []*s3c continue } - apiObjects = append(apiObjects, apiObject) + apiObjects = append(apiObjects, *apiObject) } return apiObjects } -func expandObjectLambdaContentTransformation(tfMap map[string]interface{}) *s3control.ObjectLambdaContentTransformation { +func expandObjectLambdaContentTransformation(tfMap map[string]interface{}) types.ObjectLambdaContentTransformation { if tfMap == nil { return nil } - apiObject := &s3control.ObjectLambdaContentTransformation{} + apiObject := &types.ObjectLambdaContentTransformationMemberAwsLambda{} if v, ok := tfMap["aws_lambda"].([]interface{}); ok && len(v) > 0 { - apiObject.AwsLambda = expandLambdaTransformation(v[0].(map[string]interface{})) + apiObject.Value = expandLambdaTransformation(v[0].(map[string]interface{})) } return apiObject } -func expandLambdaTransformation(tfMap map[string]interface{}) *s3control.AwsLambdaTransformation { - if tfMap == nil { - return nil - } - - apiObject := &s3control.AwsLambdaTransformation{} +func expandLambdaTransformation(tfMap map[string]interface{}) types.AwsLambdaTransformation { + apiObject := types.AwsLambdaTransformation{} if v, ok := tfMap["function_arn"].(string); ok && v != "" { apiObject.FunctionArn = aws.String(v) @@ -433,23 +426,21 @@ func expandLambdaTransformation(tfMap map[string]interface{}) *s3control.AwsLamb return apiObject } -func flattenObjectLambdaConfiguration(apiObject *s3control.ObjectLambdaConfiguration) map[string]interface{} { +func flattenObjectLambdaConfiguration(apiObject *types.ObjectLambdaConfiguration) map[string]interface{} { if apiObject == nil { return nil } - tfMap := map[string]interface{}{} - - if v := apiObject.AllowedFeatures; v != nil { - tfMap["allowed_features"] = aws.StringValueSlice(v) + tfMap := map[string]interface{}{ + "cloud_watch_metrics_enabled": apiObject.CloudWatchMetricsEnabled, } - if v := apiObject.CloudWatchMetricsEnabled; v != nil { - tfMap["cloud_watch_metrics_enabled"] = aws.BoolValue(v) + if v := apiObject.AllowedFeatures; v != nil { + tfMap["allowed_features"] = v } if v := apiObject.SupportingAccessPoint; v != nil { - tfMap["supporting_access_point"] = aws.StringValue(v) + tfMap["supporting_access_point"] = aws.ToString(v) } if v := apiObject.TransformationConfigurations; v != nil { @@ -459,15 +450,11 @@ func flattenObjectLambdaConfiguration(apiObject *s3control.ObjectLambdaConfigura return tfMap } -func flattenObjectLambdaTransformationConfiguration(apiObject *s3control.ObjectLambdaTransformationConfiguration) map[string]interface{} { - if apiObject == nil { - return nil - } - +func flattenObjectLambdaTransformationConfiguration(apiObject types.ObjectLambdaTransformationConfiguration) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.Actions; v != nil { - tfMap["actions"] = aws.StringValueSlice(v) + tfMap["actions"] = v } if v := apiObject.ContentTransformation; v != nil { @@ -477,7 +464,7 @@ func flattenObjectLambdaTransformationConfiguration(apiObject *s3control.ObjectL return tfMap } -func flattenObjectLambdaTransformationConfigurations(apiObjects []*s3control.ObjectLambdaTransformationConfiguration) []interface{} { +func flattenObjectLambdaTransformationConfigurations(apiObjects []types.ObjectLambdaTransformationConfiguration) []interface{} { if len(apiObjects) == 0 { return nil } @@ -485,43 +472,31 @@ func flattenObjectLambdaTransformationConfigurations(apiObjects []*s3control.Obj var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - tfList = append(tfList, flattenObjectLambdaTransformationConfiguration(apiObject)) } return tfList } -func flattenObjectLambdaContentTransformation(apiObject *s3control.ObjectLambdaContentTransformation) map[string]interface{} { - if apiObject == nil { - return nil - } - +func flattenObjectLambdaContentTransformation(apiObject types.ObjectLambdaContentTransformation) map[string]interface{} { tfMap := map[string]interface{}{} - if v := apiObject.AwsLambda; v != nil { - tfMap["aws_lambda"] = []interface{}{flattenLambdaTransformation(v)} + if v, ok := apiObject.(*types.ObjectLambdaContentTransformationMemberAwsLambda); ok { + tfMap["aws_lambda"] = []interface{}{flattenLambdaTransformation(v.Value)} } return tfMap } -func flattenLambdaTransformation(apiObject *s3control.AwsLambdaTransformation) map[string]interface{} { - if apiObject == nil { - return nil - } - +func flattenLambdaTransformation(apiObject types.AwsLambdaTransformation) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.FunctionArn; v != nil { - tfMap["function_arn"] = aws.StringValue(v) + tfMap["function_arn"] = aws.ToString(v) } if v := apiObject.FunctionPayload; v != nil { - tfMap["function_payload"] = aws.StringValue(v) + tfMap["function_payload"] = aws.ToString(v) } return tfMap diff --git a/internal/service/s3control/object_lambda_access_point_policy.go b/internal/service/s3control/object_lambda_access_point_policy.go index 6a44bef7e12..b6d23f01180 100644 --- a/internal/service/s3control/object_lambda_access_point_policy.go +++ b/internal/service/s3control/object_lambda_access_point_policy.go @@ -7,9 +7,10 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3control" - "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/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -64,47 +65,45 @@ func resourceObjectLambdaAccessPointPolicy() *schema.Resource { } func resourceObjectLambdaAccessPointPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) + + policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) + if err != nil { + return diag.FromErr(err) + } accountID := meta.(*conns.AWSClient).AccountID if v, ok := d.GetOk("account_id"); ok { accountID = v.(string) } name := d.Get("name").(string) - resourceID := ObjectLambdaAccessPointCreateResourceID(accountID, name) - - policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) - if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) - } - + id := ObjectLambdaAccessPointCreateResourceID(accountID, name) input := &s3control.PutAccessPointPolicyForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyForObjectLambdaWithContext(ctx, input) + _, err = conn.PutAccessPointPolicyForObjectLambda(ctx, input) if err != nil { - return diag.Errorf("creating S3 Object Lambda Access Point (%s) Policy: %s", resourceID, err) + return diag.Errorf("creating S3 Object Lambda Access Point (%s) Policy: %s", id, err) } - d.SetId(resourceID) + d.SetId(id) return resourceObjectLambdaAccessPointPolicyRead(ctx, d, meta) } func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - policy, status, err := FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) + policy, status, err := findObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Object Lambda Access Point Policy (%s) not found, removing from state", d.Id()) @@ -135,17 +134,16 @@ func resourceObjectLambdaAccessPointPolicyRead(ctx context.Context, d *schema.Re } func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) if err != nil { - return diag.Errorf("policy (%s) is invalid JSON: %s", d.Get("policy").(string), err) + return diag.FromErr(err) } input := &s3control.PutAccessPointPolicyForObjectLambdaInput{ @@ -154,7 +152,7 @@ func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema. Policy: aws.String(policy), } - _, err = conn.PutAccessPointPolicyForObjectLambdaWithContext(ctx, input) + _, err = conn.PutAccessPointPolicyForObjectLambda(ctx, input) if err != nil { return diag.Errorf("updating S3 Object Lambda Access Point Policy (%s): %s", d.Id(), err) @@ -164,16 +162,15 @@ func resourceObjectLambdaAccessPointPolicyUpdate(ctx context.Context, d *schema. } func resourceObjectLambdaAccessPointPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - conn := meta.(*conns.AWSClient).S3ControlConn(ctx) + conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, name, err := ObjectLambdaAccessPointParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } log.Printf("[DEBUG] Deleting S3 Object Lambda Access Point Policy: %s", d.Id()) - _, err = conn.DeleteAccessPointPolicyForObjectLambdaWithContext(ctx, &s3control.DeleteAccessPointPolicyForObjectLambdaInput{ + _, err = conn.DeleteAccessPointPolicyForObjectLambda(ctx, &s3control.DeleteAccessPointPolicyForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), }) @@ -189,18 +186,18 @@ func resourceObjectLambdaAccessPointPolicyDelete(ctx context.Context, d *schema. return nil } -func FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3control.S3Control, accountID string, name string) (string, *s3control.PolicyStatus, error) { - input1 := &s3control.GetAccessPointPolicyForObjectLambdaInput{ +func findObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, conn *s3control.Client, accountID, name string) (string, *types.PolicyStatus, error) { + inputGAPPFOL := &s3control.GetAccessPointPolicyForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output1, err := conn.GetAccessPointPolicyForObjectLambdaWithContext(ctx, input1) + outputGAPPFOL, err := conn.GetAccessPointPolicyForObjectLambda(ctx, inputGAPPFOL) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { return "", nil, &retry.NotFoundError{ LastError: err, - LastRequest: input1, + LastRequest: inputGAPPFOL, } } @@ -208,27 +205,27 @@ func FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, return "", nil, err } - if output1 == nil { - return "", nil, tfresource.NewEmptyResultError(input1) + if outputGAPPFOL == nil { + return "", nil, tfresource.NewEmptyResultError(inputGAPPFOL) } - policy := aws.StringValue(output1.Policy) + policy := aws.ToString(outputGAPPFOL.Policy) if policy == "" { - return "", nil, tfresource.NewEmptyResultError(input1) + return "", nil, tfresource.NewEmptyResultError(inputGAPPFOL) } - input2 := &s3control.GetAccessPointPolicyStatusForObjectLambdaInput{ + inputGAPPSFOL := &s3control.GetAccessPointPolicyStatusForObjectLambdaInput{ AccountId: aws.String(accountID), Name: aws.String(name), } - output2, err := conn.GetAccessPointPolicyStatusForObjectLambdaWithContext(ctx, input2) + outputGAPPSFOL, err := conn.GetAccessPointPolicyStatusForObjectLambda(ctx, inputGAPPSFOL) if tfawserr.ErrCodeEquals(err, errCodeNoSuchAccessPoint, errCodeNoSuchAccessPointPolicy) { return "", nil, &retry.NotFoundError{ LastError: err, - LastRequest: input2, + LastRequest: inputGAPPSFOL, } } @@ -236,9 +233,9 @@ func FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx context.Context, return "", nil, err } - if output2 == nil || output2.PolicyStatus == nil { - return "", nil, tfresource.NewEmptyResultError(input2) + if outputGAPPSFOL == nil || outputGAPPSFOL.PolicyStatus == nil { + return "", nil, tfresource.NewEmptyResultError(inputGAPPSFOL) } - return policy, output2.PolicyStatus, nil + return policy, outputGAPPSFOL.PolicyStatus, nil } diff --git a/internal/service/s3control/object_lambda_access_point_policy_test.go b/internal/service/s3control/object_lambda_access_point_policy_test.go index bd29dc4d5d5..28effe0310c 100644 --- a/internal/service/s3control/object_lambda_access_point_policy_test.go +++ b/internal/service/s3control/object_lambda_access_point_policy_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/s3control" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,6 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlObjectLambdaAccessPointPolicy_basic(t *testing.T) { @@ -25,7 +25,7 @@ func TestAccS3ControlObjectLambdaAccessPointPolicy_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -55,7 +55,7 @@ func TestAccS3ControlObjectLambdaAccessPointPolicy_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -79,7 +79,7 @@ func TestAccS3ControlObjectLambdaAccessPointPolicy_Disappears_accessPoint(t *tes resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -102,7 +102,7 @@ func TestAccS3ControlObjectLambdaAccessPointPolicy_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx), Steps: []resource.TestStep{ @@ -137,7 +137,7 @@ func TestAccS3ControlObjectLambdaAccessPointPolicy_update(t *testing.T) { func testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_object_lambda_access_point_policy" { @@ -145,7 +145,6 @@ func testAccCheckObjectLambdaAccessPointPolicyDestroy(ctx context.Context) resou } accountID, name, err := tfs3control.ObjectLambdaAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -174,17 +173,12 @@ func testAccCheckObjectLambdaAccessPointPolicyExists(ctx context.Context, n stri return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Object Lambda Access Point Policy ID is set") - } - accountID, name, err := tfs3control.ObjectLambdaAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) _, _, err = tfs3control.FindObjectLambdaAccessPointPolicyAndStatusByTwoPartKey(ctx, conn, accountID, name) diff --git a/internal/service/s3control/object_lambda_access_point_test.go b/internal/service/s3control/object_lambda_access_point_test.go index 03a64c06b52..93a4ce0e242 100644 --- a/internal/service/s3control/object_lambda_access_point_test.go +++ b/internal/service/s3control/object_lambda_access_point_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/service/s3control/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" @@ -17,11 +17,12 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlObjectLambdaAccessPoint_basic(t *testing.T) { ctx := acctest.Context(t) - var v s3control.ObjectLambdaConfiguration + var v types.ObjectLambdaConfiguration rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_s3control_object_lambda_access_point.test" accessPointResourceName := "aws_s3_access_point.test" @@ -29,7 +30,7 @@ func TestAccS3ControlObjectLambdaAccessPoint_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -66,13 +67,13 @@ func TestAccS3ControlObjectLambdaAccessPoint_basic(t *testing.T) { func TestAccS3ControlObjectLambdaAccessPoint_disappears(t *testing.T) { ctx := acctest.Context(t) - var v s3control.ObjectLambdaConfiguration + var v types.ObjectLambdaConfiguration rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_s3control_object_lambda_access_point.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -90,7 +91,7 @@ func TestAccS3ControlObjectLambdaAccessPoint_disappears(t *testing.T) { func TestAccS3ControlObjectLambdaAccessPoint_update(t *testing.T) { ctx := acctest.Context(t) - var v s3control.ObjectLambdaConfiguration + var v types.ObjectLambdaConfiguration rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_s3control_object_lambda_access_point.test" accessPointResourceName := "aws_s3_access_point.test" @@ -98,7 +99,7 @@ func TestAccS3ControlObjectLambdaAccessPoint_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckObjectLambdaAccessPointDestroy(ctx), Steps: []resource.TestStep{ @@ -157,7 +158,7 @@ func TestAccS3ControlObjectLambdaAccessPoint_update(t *testing.T) { func testAccCheckObjectLambdaAccessPointDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_s3control_object_lambda_access_point" { @@ -165,7 +166,6 @@ func testAccCheckObjectLambdaAccessPointDestroy(ctx context.Context) resource.Te } accountID, name, err := tfs3control.ObjectLambdaAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -187,24 +187,19 @@ func testAccCheckObjectLambdaAccessPointDestroy(ctx context.Context) resource.Te } } -func testAccCheckObjectLambdaAccessPointExists(ctx context.Context, n string, v *s3control.ObjectLambdaConfiguration) resource.TestCheckFunc { +func testAccCheckObjectLambdaAccessPointExists(ctx context.Context, n string, v *types.ObjectLambdaConfiguration) 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 S3 Object Lambda Access Point ID is set") - } - accountID, name, err := tfs3control.ObjectLambdaAccessPointParseResourceID(rs.Primary.ID) - if err != nil { return err } - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx) output, err := tfs3control.FindObjectLambdaAccessPointConfigurationByTwoPartKey(ctx, conn, accountID, name) diff --git a/internal/service/s3control/storage_lens_configuration.go b/internal/service/s3control/storage_lens_configuration.go index dede01d7018..695e0098115 100644 --- a/internal/service/s3control/storage_lens_configuration.go +++ b/internal/service/s3control/storage_lens_configuration.go @@ -5,16 +5,15 @@ package s3control import ( "context" - "errors" "fmt" "log" - nethttp "net/http" + "net/http" "strings" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/transport/http" "github.com/aws/aws-sdk-go-v2/service/s3control" "github.com/aws/aws-sdk-go-v2/service/s3control/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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" @@ -403,11 +402,10 @@ func resourceStorageLensConfigurationCreate(ctx context.Context, d *schema.Resou } configID := d.Get("config_id").(string) id := StorageLensConfigurationCreateResourceID(accountID, configID) - input := &s3control.PutStorageLensConfigurationInput{ AccountId: aws.String(accountID), ConfigId: aws.String(configID), - Tags: StorageLensTags(KeyValueTags(ctx, getTagsIn(ctx))), + Tags: storageLensTags(KeyValueTags(ctx, getTagsIn(ctx))), } if v, ok := d.GetOk("storage_lens_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -430,12 +428,11 @@ func resourceStorageLensConfigurationRead(ctx context.Context, d *schema.Resourc conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } - output, err := FindStorageLensConfigurationByAccountIDAndConfigID(ctx, conn, accountID, configID) + output, err := findStorageLensConfigurationByAccountIDAndConfigID(ctx, conn, accountID, configID) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] S3 Storage Lens Configuration (%s) not found, removing from state", d.Id()) @@ -469,7 +466,6 @@ func resourceStorageLensConfigurationUpdate(ctx context.Context, d *schema.Resou conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -507,7 +503,6 @@ func resourceStorageLensConfigurationDelete(ctx context.Context, d *schema.Resou conn := meta.(*conns.AWSClient).S3ControlClient(ctx) accountID, configID, err := StorageLensConfigurationParseResourceID(d.Id()) - if err != nil { return diag.FromErr(err) } @@ -518,6 +513,10 @@ func resourceStorageLensConfigurationDelete(ctx context.Context, d *schema.Resou ConfigId: aws.String(configID), }) + if tfawserr.ErrHTTPStatusCodeEquals(err, http.StatusNotFound) { + return nil + } + if err != nil { return diag.Errorf("deleting S3 Storage Lens Configuration (%s): %s", d.Id(), err) } @@ -544,7 +543,7 @@ func StorageLensConfigurationParseResourceID(id string) (string, string, error) return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected account-id%[2]sconfig-id", id, storageLensConfigurationResourceIDSeparator) } -func FindStorageLensConfigurationByAccountIDAndConfigID(ctx context.Context, conn *s3control.Client, accountID, configID string) (*types.StorageLensConfiguration, error) { +func findStorageLensConfigurationByAccountIDAndConfigID(ctx context.Context, conn *s3control.Client, accountID, configID string) (*types.StorageLensConfiguration, error) { input := &s3control.GetStorageLensConfigurationInput{ AccountId: aws.String(accountID), ConfigId: aws.String(configID), @@ -552,9 +551,7 @@ func FindStorageLensConfigurationByAccountIDAndConfigID(ctx context.Context, con output, err := conn.GetStorageLensConfiguration(ctx, input) - // No types.NoSuchConfiguration defined. - var re *http.ResponseError - if errors.As(err, &re) && re.Response.StatusCode == nethttp.StatusNotFound { + if tfawserr.ErrHTTPStatusCodeEquals(err, http.StatusNotFound) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -572,7 +569,7 @@ func FindStorageLensConfigurationByAccountIDAndConfigID(ctx context.Context, con return output.StorageLensConfiguration, nil } -func StorageLensTags(tags tftags.KeyValueTags) []types.StorageLensTag { +func storageLensTags(tags tftags.KeyValueTags) []types.StorageLensTag { result := make([]types.StorageLensTag, 0, len(tags)) for k, v := range tags.Map() { @@ -587,7 +584,7 @@ func StorageLensTags(tags tftags.KeyValueTags) []types.StorageLensTag { return result } -func KeyValueTagsFromStorageLensTags(ctx context.Context, tags []types.StorageLensTag) tftags.KeyValueTags { +func keyValueTagsFromStorageLensTags(ctx context.Context, tags []types.StorageLensTag) tftags.KeyValueTags { m := make(map[string]*string, len(tags)) for _, tag := range tags { @@ -609,7 +606,7 @@ func storageLensConfigurationListTags(ctx context.Context, conn *s3control.Clien return tftags.New(ctx, nil), err } - return KeyValueTagsFromStorageLensTags(ctx, output.Tags), nil + return keyValueTagsFromStorageLensTags(ctx, output.Tags), nil } func storageLensConfigurationUpdateTags(ctx context.Context, conn *s3control.Client, accountID, configID string, oldTagsMap, newTagsMap any) error { @@ -629,7 +626,7 @@ func storageLensConfigurationUpdateTags(ctx context.Context, conn *s3control.Cli input := &s3control.PutStorageLensConfigurationTaggingInput{ AccountId: aws.String(accountID), ConfigId: aws.String(configID), - Tags: StorageLensTags(newTags.Merge(ignoredTags)), + Tags: storageLensTags(newTags.Merge(ignoredTags)), } _, err := conn.PutStorageLensConfigurationTagging(ctx, input) diff --git a/internal/service/s3control/storage_lens_configuration_test.go b/internal/service/s3control/storage_lens_configuration_test.go index cd123bf51da..d8e3e93928a 100644 --- a/internal/service/s3control/storage_lens_configuration_test.go +++ b/internal/service/s3control/storage_lens_configuration_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/s3control" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,6 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfs3control "github.com/hashicorp/terraform-provider-aws/internal/service/s3control" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccS3ControlStorageLensConfiguration_basic(t *testing.T) { @@ -25,7 +25,7 @@ func TestAccS3ControlStorageLensConfiguration_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckStorageLensConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -71,7 +71,7 @@ func TestAccS3ControlStorageLensConfiguration_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckStorageLensConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -94,7 +94,7 @@ func TestAccS3ControlStorageLensConfiguration_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckStorageLensConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -139,7 +139,7 @@ func TestAccS3ControlStorageLensConfiguration_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckStorageLensConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -245,7 +245,7 @@ func TestAccS3ControlStorageLensConfiguration_advancedMetrics(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, s3control.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.S3ControlEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckStorageLensConfigurationDestroy(ctx), Steps: []resource.TestStep{ @@ -334,7 +334,6 @@ func testAccCheckStorageLensConfigurationDestroy(ctx context.Context) resource.T } accountID, configID, err := tfs3control.StorageLensConfigurationParseResourceID(rs.Primary.ID) - if err != nil { return err } @@ -363,12 +362,7 @@ func testAccCheckStorageLensConfigurationExists(ctx context.Context, n string) r return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No S3 Storage Lens Configuration ID is set") - } - accountID, configID, err := tfs3control.StorageLensConfigurationParseResourceID(rs.Primary.ID) - if err != nil { return err } diff --git a/internal/service/s3control/sweep.go b/internal/service/s3control/sweep.go index 14c3cd840be..f7f25eb501d 100644 --- a/internal/service/s3control/sweep.go +++ b/internal/service/s3control/sweep.go @@ -10,12 +10,13 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3control" multierror "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" + "github.com/hashicorp/terraform-provider-aws/names" ) func init() { @@ -49,7 +50,7 @@ func sweepAccessPoints(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.S3ControlConn(ctx) + conn := client.S3ControlClient(ctx) accountID := client.AccountID input := &s3control.ListAccessPointsInput{ AccountId: aws.String(accountID), @@ -57,15 +58,23 @@ func sweepAccessPoints(region string) error { sweepResources := make([]sweep.Sweepable, 0) var sweeperErrs *multierror.Error - err = conn.ListAccessPointsPagesWithContext(ctx, input, func(page *s3control.ListAccessPointsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := s3control.NewListAccessPointsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping S3 Access Point sweep for %s: %s", region, err) + return sweeperErrs.ErrorOrNil() + } + + if err != nil { + return fmt.Errorf("error listing S3 Access Points (%s): %w", region, err) } for _, v := range page.AccessPointList { r := resourceAccessPoint() d := r.Data(nil) - if id, err := AccessPointCreateResourceID(aws.StringValue(v.AccessPointArn)); err != nil { + if id, err := AccessPointCreateResourceID(aws.ToString(v.AccessPointArn)); err != nil { sweeperErrs = multierror.Append(sweeperErrs, err) continue } else { @@ -74,17 +83,6 @@ func sweepAccessPoints(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping S3 Access Point sweep for %s: %s", region, err) - return sweeperErrs.ErrorOrNil() - } - - if err != nil { - return fmt.Errorf("error listing S3 Access Points (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -98,45 +96,41 @@ func sweepAccessPoints(region string) error { func sweepMultiRegionAccessPoints(region string) error { ctx := sweep.Context(region) - if region != endpoints.UsWest2RegionID { + if region != names.USWest2RegionID { log.Printf("[WARN] Skipping S3 Multi-Region Access Point sweep for region: %s", region) return nil } - client, err := sweep.SharedRegionalSweepClient(ctx, region) if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.S3ControlConn(ctx) + conn := client.S3ControlClient(ctx) accountID := client.AccountID input := &s3control.ListMultiRegionAccessPointsInput{ AccountId: aws.String(accountID), } sweepResources := make([]sweep.Sweepable, 0) - err = conn.ListMultiRegionAccessPointsPagesWithContext(ctx, input, func(page *s3control.ListMultiRegionAccessPointsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := s3control.NewListMultiRegionAccessPointsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping S3 Multi-Region Access Point sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing S3 Multi-Region Access Points (%s): %w", region, err) } for _, v := range page.AccessPoints { r := resourceMultiRegionAccessPoint() d := r.Data(nil) - d.SetId(MultiRegionAccessPointCreateResourceID(accountID, aws.StringValue(v.Name))) + d.SetId(MultiRegionAccessPointCreateResourceID(accountID, aws.ToString(v.Name))) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping S3 Multi-Region Access Point sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing S3 Multi-Region Access Points (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -154,36 +148,33 @@ func sweepObjectLambdaAccessPoints(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.S3ControlConn(ctx) + conn := client.S3ControlClient(ctx) accountID := client.AccountID input := &s3control.ListAccessPointsForObjectLambdaInput{ AccountId: aws.String(accountID), } sweepResources := make([]sweep.Sweepable, 0) - conn.ListAccessPointsForObjectLambdaPagesWithContext(ctx, input, func(page *s3control.ListAccessPointsForObjectLambdaOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := s3control.NewListAccessPointsForObjectLambdaPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping S3 Object Lambda Access Point sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing S3 Object Lambda Access Points (%s): %w", region, err) } for _, v := range page.ObjectLambdaAccessPointList { r := resourceObjectLambdaAccessPoint() d := r.Data(nil) - d.SetId(ObjectLambdaAccessPointCreateResourceID(accountID, aws.StringValue(v.Name))) + d.SetId(ObjectLambdaAccessPointCreateResourceID(accountID, aws.ToString(v.Name))) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping S3 Object Lambda Access Point sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing S3 Object Lambda Access Points (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -201,20 +192,28 @@ func sweepStorageLensConfigurations(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.S3ControlConn(ctx) + conn := client.S3ControlClient(ctx) accountID := client.AccountID input := &s3control.ListStorageLensConfigurationsInput{ AccountId: aws.String(accountID), } sweepResources := make([]sweep.Sweepable, 0) - conn.ListStorageLensConfigurationsPagesWithContext(ctx, input, func(page *s3control.ListStorageLensConfigurationsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := s3control.NewListStorageLensConfigurationsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping S3 Storage Lens Configuration sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing S3 Storage Lens Configurations (%s): %w", region, err) } for _, v := range page.StorageLensConfigurationList { - configID := aws.StringValue(v.Id) + configID := aws.ToString(v.Id) if configID == "default-account-dashboard" { continue @@ -226,17 +225,6 @@ func sweepStorageLensConfigurations(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping S3 Storage Lens Configuration sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing S3 Storage Lens Configurations (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) diff --git a/internal/service/s3control/tags_gen.go b/internal/service/s3control/tags_gen.go index 720217ef2ae..c36f25b0dbf 100644 --- a/internal/service/s3control/tags_gen.go +++ b/internal/service/s3control/tags_gen.go @@ -4,8 +4,8 @@ package s3control import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3control" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/s3control/types" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/types" ) @@ -13,11 +13,11 @@ import ( // []*SERVICE.Tag handling // Tags returns s3control service tags. -func Tags(tags tftags.KeyValueTags) []*s3control.S3Tag { - result := make([]*s3control.S3Tag, 0, len(tags)) +func Tags(tags tftags.KeyValueTags) []awstypes.S3Tag { + result := make([]awstypes.S3Tag, 0, len(tags)) for k, v := range tags.Map() { - tag := &s3control.S3Tag{ + tag := awstypes.S3Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -29,11 +29,11 @@ func Tags(tags tftags.KeyValueTags) []*s3control.S3Tag { } // KeyValueTags creates tftags.KeyValueTags from s3control service tags. -func KeyValueTags(ctx context.Context, tags []*s3control.S3Tag) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags []awstypes.S3Tag) 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) @@ -41,7 +41,7 @@ func KeyValueTags(ctx context.Context, tags []*s3control.S3Tag) tftags.KeyValueT // getTagsIn returns s3control service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*s3control.S3Tag { +func getTagsIn(ctx context.Context) []awstypes.S3Tag { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -52,7 +52,7 @@ func getTagsIn(ctx context.Context) []*s3control.S3Tag { } // setTagsOut sets s3control service tags in Context. -func setTagsOut(ctx context.Context, tags []*s3control.S3Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.S3Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = types.Some(KeyValueTags(ctx, tags)) } diff --git a/internal/tfresource/retry.go b/internal/tfresource/retry.go index f8e1f5bd65d..114b0c55229 100644 --- a/internal/tfresource/retry.go +++ b/internal/tfresource/retry.go @@ -59,18 +59,7 @@ func RetryWhen(ctx context.Context, timeout time.Duration, f func() (interface{} // RetryWhenAWSErrCodeEquals retries the specified function when it returns one of the specified AWS error code. func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr.ErrCodeEquals(err, codes...) { - return true, err - } - - return false, err - }) -} - -// RetryWhenAWSErrCodeEqualsV2 retries the specified function when it returns one of the specified AWS SDK for Go v2 error code. -func RetryWhenAWSErrCodeEqualsV2(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name - return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr_sdkv2.ErrCodeEquals(err, codes...) { + if tfawserr.ErrCodeEquals(err, codes...) || tfawserr_sdkv2.ErrCodeEquals(err, codes...) { return true, err } @@ -81,18 +70,7 @@ func RetryWhenAWSErrCodeEqualsV2(ctx context.Context, timeout time.Duration, f f // RetryWhenAWSErrMessageContains retries the specified function when it returns an AWS error containing the specified message. func RetryWhenAWSErrMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code, message string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr.ErrMessageContains(err, code, message) { - return true, err - } - - return false, err - }) -} - -// RetryWhenAWSErrMessageContainsV2 retries the specified function when it returns an AWS SDK for Go v2 error containing the specified message. -func RetryWhenAWSErrMessageContainsV2(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code, message string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name - return RetryWhen(ctx, timeout, f, func(err error) (bool, error) { - if tfawserr_sdkv2.ErrMessageContains(err, code, message) { + if tfawserr.ErrMessageContains(err, code, message) || tfawserr_sdkv2.ErrMessageContains(err, code, message) { return true, err } diff --git a/names/names.go b/names/names.go index 1153edc0d93..101d272f568 100644 --- a/names/names.go +++ b/names/names.go @@ -23,7 +23,7 @@ import ( "strings" ) -// This "should" be defined by the AWS Go SDK v2, but currently isn't. +// These "should" be defined by the AWS Go SDK v2, but currently aren't. const ( AccessAnalyzerEndpointID = "access-analyzer" AccountEndpointID = "account" @@ -57,6 +57,7 @@ const ( Route53DomainsEndpointID = "route53domains" SchedulerEndpointID = "scheduler" S3EndpointID = "s3" + S3ControlEndpointID = "s3-control" SESV2EndpointID = "sesv2" SSMEndpointID = "ssm" SSMContactsEndpointID = "ssm-contacts" @@ -68,6 +69,17 @@ const ( XRayEndpointID = "xray" ) +// These should move to aws-sdk-go-base. +// See https://github.com/hashicorp/aws-sdk-go-base/issues/649. +const ( + StandardPartitionID = "aws" // AWS Standard partition. + USGovCloudPartitionID = "aws-us-gov" // AWS GovCloud (US) partition. +) + +const ( + USWest2RegionID = "us-west-2" // US West (Oregon). +) + // Type ServiceDatum corresponds closely to columns in `names_data.csv` and are // described in detail in README.md. type ServiceDatum struct { diff --git a/website/docs/d/s3control_multi_region_access_point.html.markdown b/website/docs/d/s3control_multi_region_access_point.html.markdown index 3dec9ca0d86..24e1f4a7910 100644 --- a/website/docs/d/s3control_multi_region_access_point.html.markdown +++ b/website/docs/d/s3control_multi_region_access_point.html.markdown @@ -53,4 +53,5 @@ This data source exports the following attributes in addition to the arguments a ### regions * `bucket` - The name of the bucket. +* `bucket_account_id` - The AWS account ID that owns the bucket. * `region` - The name of the region. diff --git a/website/docs/r/s3control_multi_region_access_point.html.markdown b/website/docs/r/s3control_multi_region_access_point.html.markdown index c7f4b3d139d..3d0563b4c6c 100644 --- a/website/docs/r/s3control_multi_region_access_point.html.markdown +++ b/website/docs/r/s3control_multi_region_access_point.html.markdown @@ -96,6 +96,7 @@ The `public_access_block` block supports the following: The `region` block supports the following: * `bucket` - (Required) The name of the associated bucket for the Region. +* `bucket_account_id` - (Optional) The AWS account ID that owns the Amazon S3 bucket that's associated with this Multi-Region Access Point. ## Attribute Reference