Skip to content

Commit

Permalink
Merge pull request #34525 from hashicorp/td-s3control-all-aws-sdk-go-v2
Browse files Browse the repository at this point in the history
`aws_s3_account_public_access_block`: Migrate to AWS SDK for Go v2
  • Loading branch information
ewbankkit authored Nov 22, 2023
2 parents 9866968 + 846e568 commit 506f81f
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 81 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c
github.com/YakDriver/regexache v0.23.0
github.com/aws/aws-sdk-go v1.48.2
github.com/aws/aws-sdk-go v1.48.3
github.com/aws/aws-sdk-go-v2 v1.23.1
github.com/aws/aws-sdk-go-v2/config v1.25.5
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.5
Expand Down Expand Up @@ -70,7 +70,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.5.3
github.com/aws/aws-sdk-go-v2/service/route53domains v1.19.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.44.0
github.com/aws/aws-sdk-go-v2/service/s3control v1.37.1
github.com/aws/aws-sdk-go-v2/service/s3control v1.38.0
github.com/aws/aws-sdk-go-v2/service/scheduler v1.5.3
github.com/aws/aws-sdk-go-v2/service/securitylake v1.9.3
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.18.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmms
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.48.2 h1:Lf7+Y4WmHB0AQLRQZA46diSwDa+LWbwY6IGaYoCVtTc=
github.com/aws/aws-sdk-go v1.48.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.48.3 h1:btYjT+opVFxUbRz+qSCjJe07cdX82BHmMX/FXYmoL7g=
github.com/aws/aws-sdk-go v1.48.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.23.1 h1:qXaFsOOMA+HsZtX8WoCa+gJnbyW7qyFFBlPqvTSzbaI=
github.com/aws/aws-sdk-go-v2 v1.23.1/go.mod h1:i1XDttT4rnf6vxc9AuskLc6s7XBee8rlLilKlc03uAA=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.1 h1:ZY3108YtBNq96jNZTICHxN1gSBSbnvIdYwwqnvCV4Mc=
Expand Down Expand Up @@ -178,8 +178,8 @@ github.com/aws/aws-sdk-go-v2/service/route53domains v1.19.3 h1:bE+M7fO3XpUjcyFEj
github.com/aws/aws-sdk-go-v2/service/route53domains v1.19.3/go.mod h1:5yfMeHnHhHK8WpajhjfhxpJteaxW045jdSsK2eH32Pc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.44.0 h1:FJTWR2nP1ddLIbk4n7Glw8wGbeWGHaViUwADPzE/EBo=
github.com/aws/aws-sdk-go-v2/service/s3 v1.44.0/go.mod h1:dqJ5JBL0clzgHriH35Amx3LRFY6wNIPUX7QO/BerSBo=
github.com/aws/aws-sdk-go-v2/service/s3control v1.37.1 h1:/xPHgvArPO+N96lju2XSpxtKFn9MPiO9I5k7nlEEg/4=
github.com/aws/aws-sdk-go-v2/service/s3control v1.37.1/go.mod h1:A2vCti/i+W0KkUwDAY3jio5QpuS/tk4jhmBaTDoZ1aY=
github.com/aws/aws-sdk-go-v2/service/s3control v1.38.0 h1:Aq6Awfh9OcA5XSyouZW5ouv6g2D6IsPgmals2GdpfyI=
github.com/aws/aws-sdk-go-v2/service/s3control v1.38.0/go.mod h1:A2vCti/i+W0KkUwDAY3jio5QpuS/tk4jhmBaTDoZ1aY=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.5.3 h1:XPNfnBEZ0uIyYQ6XrYceD+BlaC1LEyjntRYn2a8dW/8=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.5.3/go.mod h1:0BCVZduXl+TWsNMMVEhMSv+0HmVxgHkMkMtZFKEh2Xw=
github.com/aws/aws-sdk-go-v2/service/securitylake v1.9.3 h1:cFfqbyJ/LQ3lhx11tMBSx1v3I8xG+tsRXekaPn5iRrs=
Expand Down
5 changes: 0 additions & 5 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions internal/service/s3control/account_public_access_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"reflect"
"strconv"

"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"
Expand All @@ -20,7 +21,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

// @SDKResource("aws_s3_account_public_access_block")
// @SDKResource("aws_s3_account_public_access_block", name="Account Public Access Block")
func resourceAccountPublicAccessBlock() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAccountPublicAccessBlockCreate,
Expand Down Expand Up @@ -65,7 +66,7 @@ func resourceAccountPublicAccessBlock() *schema.Resource {
}

func resourceAccountPublicAccessBlockCreate(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 {
Expand All @@ -74,15 +75,15 @@ func resourceAccountPublicAccessBlockCreate(ctx context.Context, d *schema.Resou

input := &s3control.PutPublicAccessBlockInput{
AccountId: aws.String(accountID),
PublicAccessBlockConfiguration: &s3control.PublicAccessBlockConfiguration{
PublicAccessBlockConfiguration: &types.PublicAccessBlockConfiguration{
BlockPublicAcls: aws.Bool(d.Get("block_public_acls").(bool)),
BlockPublicPolicy: aws.Bool(d.Get("block_public_policy").(bool)),
IgnorePublicAcls: aws.Bool(d.Get("ignore_public_acls").(bool)),
RestrictPublicBuckets: aws.Bool(d.Get("restrict_public_buckets").(bool)),
},
}

_, err := conn.PutPublicAccessBlockWithContext(ctx, input)
_, err := conn.PutPublicAccessBlock(ctx, input)

if err != nil {
return diag.Errorf("creating S3 Account Public Access Block (%s): %s", accountID, err)
Expand All @@ -102,7 +103,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)
conn := meta.(*conns.AWSClient).S3ControlClient(ctx)

output, err := findPublicAccessBlockByAccountID(ctx, conn, d.Id())

Expand All @@ -126,9 +127,9 @@ func resourceAccountPublicAccessBlockRead(ctx context.Context, d *schema.Resourc
}

func resourceAccountPublicAccessBlockUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).S3ControlConn(ctx)
conn := meta.(*conns.AWSClient).S3ControlClient(ctx)

publicAccessBlockConfiguration := &s3control.PublicAccessBlockConfiguration{
publicAccessBlockConfiguration := &types.PublicAccessBlockConfiguration{
BlockPublicAcls: aws.Bool(d.Get("block_public_acls").(bool)),
BlockPublicPolicy: aws.Bool(d.Get("block_public_policy").(bool)),
IgnorePublicAcls: aws.Bool(d.Get("ignore_public_acls").(bool)),
Expand All @@ -139,7 +140,7 @@ func resourceAccountPublicAccessBlockUpdate(ctx context.Context, d *schema.Resou
PublicAccessBlockConfiguration: publicAccessBlockConfiguration,
}

_, err := conn.PutPublicAccessBlockWithContext(ctx, input)
_, err := conn.PutPublicAccessBlock(ctx, input)

if err != nil {
return diag.Errorf("updating S3 Account Public Access Block (%s): %s", d.Id(), err)
Expand All @@ -153,14 +154,14 @@ func resourceAccountPublicAccessBlockUpdate(ctx context.Context, d *schema.Resou
}

func resourceAccountPublicAccessBlockDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).S3ControlConn(ctx)
conn := meta.(*conns.AWSClient).S3ControlClient(ctx)

log.Printf("[DEBUG] Deleting S3 Account Public Access Block: %s", d.Id())
_, err := conn.DeletePublicAccessBlockWithContext(ctx, &s3control.DeletePublicAccessBlockInput{
_, err := conn.DeletePublicAccessBlock(ctx, &s3control.DeletePublicAccessBlockInput{
AccountId: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, s3control.ErrCodeNoSuchPublicAccessBlockConfiguration) {
if tfawserr.ErrCodeEquals(err, errCodeNoSuchPublicAccessBlockConfiguration) {
return nil
}

Expand All @@ -171,14 +172,14 @@ 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.Client, accountID string) (*types.PublicAccessBlockConfiguration, error) {
input := &s3control.GetPublicAccessBlockInput{
AccountId: aws.String(accountID),
}

output, err := conn.GetPublicAccessBlockWithContext(ctx, input)
output, err := conn.GetPublicAccessBlock(ctx, input)

if tfawserr.ErrCodeEquals(err, s3control.ErrCodeNoSuchPublicAccessBlockConfiguration) {
if tfawserr.ErrCodeEquals(err, errCodeNoSuchPublicAccessBlockConfiguration) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
Expand All @@ -196,7 +197,7 @@ func findPublicAccessBlockByAccountID(ctx context.Context, conn *s3control.S3Con
return output.PublicAccessBlockConfiguration, nil
}

func statusPublicAccessBlockEqual(ctx context.Context, conn *s3control.S3Control, accountID string, target *s3control.PublicAccessBlockConfiguration) retry.StateRefreshFunc {
func statusPublicAccessBlockEqual(ctx context.Context, conn *s3control.Client, accountID string, target *types.PublicAccessBlockConfiguration) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := findPublicAccessBlockByAccountID(ctx, conn, accountID)

Expand All @@ -212,7 +213,7 @@ func statusPublicAccessBlockEqual(ctx context.Context, conn *s3control.S3Control
}
}

func waitPublicAccessBlockEqual(ctx context.Context, conn *s3control.S3Control, accountID string, target *s3control.PublicAccessBlockConfiguration) (*s3control.PublicAccessBlockConfiguration, error) {
func waitPublicAccessBlockEqual(ctx context.Context, conn *s3control.Client, accountID string, target *types.PublicAccessBlockConfiguration) (*types.PublicAccessBlockConfiguration, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{strconv.FormatBool(false)},
Target: []string{strconv.FormatBool(true)},
Expand All @@ -224,7 +225,7 @@ func waitPublicAccessBlockEqual(ctx context.Context, conn *s3control.S3Control,

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*s3control.PublicAccessBlockConfiguration); ok {
if output, ok := outputRaw.(*types.PublicAccessBlockConfiguration); ok {
return output, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

// @SDKDataSource("aws_s3_account_public_access_block")
// @SDKDataSource("aws_s3_account_public_access_block", name="Account Public Access Block")
func dataSourceAccountPublicAccessBlock() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceAccountPublicAccessBlockRead,
Expand Down Expand Up @@ -44,7 +44,7 @@ func dataSourceAccountPublicAccessBlock() *schema.Resource {
}

func dataSourceAccountPublicAccessBlockRead(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 {
Expand Down
37 changes: 19 additions & 18 deletions internal/service/s3control/account_public_access_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go/service/s3control"
"github.com/aws/aws-sdk-go-v2/service/s3control/types"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
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"
)

// S3 account-level settings must run serialized
Expand All @@ -41,12 +42,12 @@ func TestAccS3ControlAccountPublicAccessBlock_serial(t *testing.T) {

func testAccAccountPublicAccessBlock_basic(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -72,12 +73,12 @@ func testAccAccountPublicAccessBlock_basic(t *testing.T) {

func testAccAccountPublicAccessBlock_disappears(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -95,12 +96,12 @@ func testAccAccountPublicAccessBlock_disappears(t *testing.T) {

func testAccAccountPublicAccessBlock_AccountID(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -122,12 +123,12 @@ func testAccAccountPublicAccessBlock_AccountID(t *testing.T) {

func testAccAccountPublicAccessBlock_BlockPublicACLs(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -163,12 +164,12 @@ func testAccAccountPublicAccessBlock_BlockPublicACLs(t *testing.T) {

func testAccAccountPublicAccessBlock_BlockPublicPolicy(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -204,12 +205,12 @@ func testAccAccountPublicAccessBlock_BlockPublicPolicy(t *testing.T) {

func testAccAccountPublicAccessBlock_IgnorePublicACLs(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -245,12 +246,12 @@ func testAccAccountPublicAccessBlock_IgnorePublicACLs(t *testing.T) {

func testAccAccountPublicAccessBlock_RestrictPublicBuckets(t *testing.T) {
ctx := acctest.Context(t)
var v s3control.PublicAccessBlockConfiguration
var v types.PublicAccessBlockConfiguration
resourceName := "aws_s3_account_public_access_block.test"

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,
CheckDestroy: testAccCheckAccountPublicAccessBlockDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -284,14 +285,14 @@ func testAccAccountPublicAccessBlock_RestrictPublicBuckets(t *testing.T) {
})
}

func testAccCheckAccountPublicAccessBlockExists(ctx context.Context, n string, v *s3control.PublicAccessBlockConfiguration) resource.TestCheckFunc {
func testAccCheckAccountPublicAccessBlockExists(ctx context.Context, n string, v *types.PublicAccessBlockConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).S3ControlClient(ctx)

output, err := tfs3control.FindPublicAccessBlockByAccountID(ctx, conn, rs.Primary.ID)

Expand All @@ -307,7 +308,7 @@ func testAccCheckAccountPublicAccessBlockExists(ctx context.Context, n string, v

func testAccCheckAccountPublicAccessBlockDestroy(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_account_public_access_block" {
Expand Down
Loading

0 comments on commit 506f81f

Please sign in to comment.