Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3: Enable use of AWS SDK for Go v2 #33304

Merged
merged 19 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/#####.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
data-source/aws_s3_objects: Add `request_payer` argument and `request_charged` attribute
```

```release-note:enhancement
data-source/aws_s3_objects: Add plan-time validation of `encoding_type`
```

```release-note:bug
data-source/aws_s3_objects: Respect configured `max_keys` value if it's greater than `1000`
```
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/resourceexplorer2 v1.3.5
github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.3.5
github.com/aws/aws-sdk-go-v2/service/route53domains v1.17.3
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5
github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0
github.com/aws/aws-sdk-go-v2/service/scheduler v1.2.5
github.com/aws/aws-sdk-go-v2/service/securitylake v1.7.0
Expand Down Expand Up @@ -117,7 +118,10 @@ require (
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4 // indirect
github.com/aws/aws-sdk-go-v2/service/iam v1.22.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 h1:SijA0mgjV8E+8G45lt
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1g3pHAIdCp7QsRIkMmLAgoDquQ9Rr8kYw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39 h1:fc0ukRAiP1syoSGZYu+DaE+FulSYhTiJ8WpVu5jElU4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39/go.mod h1:WLAW8PT7+JhjZfLSWe7WEJaJu0GNo0cKc2Zyo003RBs=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4 h1:6lJvvkQ9HmbHZ4h/IEwclwv2mrTW8Uq1SOB/kXy0mfw=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4/go.mod h1:1PrKYwxTM+zjpw9Y41KFtoJCQrJ34Z47Y4VgVbfndjo=
github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.20.5 h1:1w0ELQMC3AptxEFS4A+vJuhyIuC9IoNN2YxNKK5pSYQ=
github.com/aws/aws-sdk-go-v2/service/accessanalyzer v1.20.5/go.mod h1:zwKhX2c7u7XDz2ToVE+qunfyoy9+3AO0rZynN5TwXCc=
github.com/aws/aws-sdk-go-v2/service/account v1.11.5 h1:UX7HDdPZwTmrr1zu1j8e9QNINZS2YSJ+DoxhnnPyJY8=
Expand Down Expand Up @@ -92,6 +94,10 @@ github.com/aws/aws-sdk-go-v2/service/identitystore v1.17.6 h1:1+CSnP3TCGEnv6D12I
github.com/aws/aws-sdk-go-v2/service/identitystore v1.17.6/go.mod h1:uP4598oNnSTY5AClqIoK6QHQnwz7cuRS8CBkVMXuxOU=
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.16.6 h1:HhLDyWzcq1QAQM9/D6r49CA1NX7mSuE77XruZ/GM0tI=
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.16.6/go.mod h1:ZThso1NAB0Pt7ZHiE8QjGxZsdSq3yE3IHTO8DSsIj0Y=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 h1:m0QTSI6pZYJTk5WSKx3fm5cNW/DCicVzULBgU/6IyD0=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14/go.mod h1:dDilntgHy9WnHXsh7dDtUPgHKEfTJIBUTHM8OWm0f/0=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 h1:eev2yZX7esGRjqRbnVk1UxMLw4CyVZDpZXRCcy75oQk=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36/go.mod h1:lGnOkH9NJATw0XEPcAknFBj3zzNTEGRHtSw+CwC1YTg=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35 h1:UKjpIDLVF90RfV88XurdduMoTxPqtGHZMIDYZQM7RO4=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35/go.mod h1:B3dUg0V6eJesUTi+m27NUkj7n8hdDKYUpxj8f4+TqaQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.32/go.mod h1:4jwAWKEkCR0anWk5+1RbfSg1R5Gzld7NLiuaq5bTR/Y=
Expand Down Expand Up @@ -141,6 +147,8 @@ github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.3.5 h1:tfmJZFDrma1cgraLRuE
github.com/aws/aws-sdk-go-v2/service/rolesanywhere v1.3.5/go.mod h1:vXPkNV5GGPdMjRRNzO45nX3qsNTgB5lP19Tk4Go30xQ=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.17.3 h1:aaHlZb06fyEQ3uqEVJiN3hLt8syCzX+tWZiz40S4c0Y=
github.com/aws/aws-sdk-go-v2/service/route53domains v1.17.3/go.mod h1:SK+5R1cYgVgSfBGi9T/gPGNIuLInF3eIRYNruia62rg=
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5 h1:A42xdtStObqy7NGvzZKpnyNXvoOmm+FENobZ0/ssHWk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5/go.mod h1:rDGMZA7f4pbmTtPOk5v5UM2lmX6UAbRnMDJeDvnH7AM=
github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0 h1:f4qHghGTcns4L4F7u8AHH6pcVLwgtTMNkNZeRJZ5xlA=
github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0/go.mod h1:YSdqo9knBVm5H3JVmWDhx9Wts9828nColUJzL3OKXDk=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.2.5 h1:AGRPn7Hef59Eb9zfXjf6MGn0xRPpO73dIV8u8pfo5Z8=
Expand Down
5 changes: 5 additions & 0 deletions internal/conns/awsclient_gen.go

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

8 changes: 0 additions & 8 deletions internal/service/s3/bucket_objects_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestAccS3BucketObjectsDataSource_basic(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "2"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/navajo/north_window"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.1", "arch/navajo/sand_dune"),
Expand All @@ -61,7 +60,6 @@ func TestAccS3BucketObjectsDataSource_basicViaAccessPoint(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_basicViaAccessPoint(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "2"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/navajo/north_window"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.1", "arch/navajo/sand_dune"),
Expand All @@ -88,7 +86,6 @@ func TestAccS3BucketObjectsDataSource_all(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_all(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "7"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/courthouse_towers/landscape"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.1", "arch/navajo/north_window"),
Expand Down Expand Up @@ -120,7 +117,6 @@ func TestAccS3BucketObjectsDataSource_prefixes(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_prefixes(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "1"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/rubicon"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "common_prefixes.#", "4"),
Expand Down Expand Up @@ -151,7 +147,6 @@ func TestAccS3BucketObjectsDataSource_encoded(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_encoded(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "2"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/ru+b+ic+on"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.1", "arch/rubicon"),
Expand All @@ -178,7 +173,6 @@ func TestAccS3BucketObjectsDataSource_maxKeys(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_maxKeys(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "2"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/courthouse_towers/landscape"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.1", "arch/navajo/north_window"),
Expand All @@ -205,7 +199,6 @@ func TestAccS3BucketObjectsDataSource_startAfter(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_startAfter(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "1"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.0", "arch/three_gossips/turret"),
),
Expand All @@ -231,7 +224,6 @@ func TestAccS3BucketObjectsDataSource_fetchOwner(t *testing.T) {
{
Config: testAccBucketObjectsDataSourceConfig_owners(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckObjectsExistsDataSource("data.aws_s3_objects.yesh"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "keys.#", "2"),
resource.TestCheckResourceAttr("data.aws_s3_objects.yesh", "owners.#", "2"),
),
Expand Down
22 changes: 10 additions & 12 deletions internal/service/s3/canonical_user_id_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ package s3

import (
"context"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

// @SDKDataSource("aws_canonical_user_id")
func DataSourceCanonicalUserID() *schema.Resource {
func dataSourceCanonicalUserID() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceCanonicalUserIDRead,

Expand All @@ -31,21 +30,20 @@ func DataSourceCanonicalUserID() *schema.Resource {

func dataSourceCanonicalUserIDRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Conn(ctx)
conn := meta.(*conns.AWSClient).S3Client(ctx)

log.Printf("[DEBUG] Reading S3 Buckets")
output, err := conn.ListBuckets(ctx, &s3.ListBucketsInput{})

req := &s3.ListBucketsInput{}
resp, err := conn.ListBucketsWithContext(ctx, req)
if err != nil {
return sdkdiag.AppendErrorf(diags, "listing S3 Buckets: %s", err)
}
if resp == nil || resp.Owner == nil {
return sdkdiag.AppendErrorf(diags, "no canonical user ID found")

if output == nil || output.Owner == nil {
return sdkdiag.AppendErrorf(diags, "S3 Canonical User ID not found")
}

d.SetId(aws.StringValue(resp.Owner.ID))
d.Set("display_name", resp.Owner.DisplayName)
d.SetId(aws.ToString(output.Owner.ID))
d.Set("display_name", output.Owner.DisplayName)

return diags
}
33 changes: 8 additions & 25 deletions internal/service/s3/canonical_user_id_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,33 @@
package s3_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/s3"
"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/names"
)

func TestAccS3CanonicalUserIDDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
dataSourceName := "data.aws_canonical_user_id.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, s3.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.S3EndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccCanonicalUserIDDataSourceConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCanonicalUserIdCheckExistsDataSource("data.aws_canonical_user_id.current"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "display_name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
),
},
},
})
}

func testAccCanonicalUserIdCheckExistsDataSource(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Can't find Canonical User ID resource: %s", name)
}

if rs.Primary.Attributes["id"] == "" {
return fmt.Errorf("Missing Canonical User ID")
}
if rs.Primary.Attributes["display_name"] == "" {
return fmt.Errorf("Missing Display Name")
}

return nil
}
}

const testAccCanonicalUserIDDataSourceConfig_basic = `
data "aws_canonical_user_id" "current" {}
data "aws_canonical_user_id" "test" {}
`
Loading
Loading