From 883dc8bfd6c1e31d4c30864b63c2c8f4989b723c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 7 Jun 2023 09:32:49 -0400 Subject: [PATCH 1/3] Remove 'AWSClient.s3ConnURICleaningDisabled'. --- internal/conns/awsclient_gen.go | 2 -- internal/generate/awsclient/file.tmpl | 2 -- 2 files changed, 4 deletions(-) diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 0052fd47e4a..821e155c1dd 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -670,8 +670,6 @@ type AWSClient struct { workspacesConn *workspaces.WorkSpaces workspaceswebConn *workspacesweb.WorkSpacesWeb xrayClient *xray.Client - - s3ConnURICleaningDisabled *s3.S3 } func (client *AWSClient) ACMClient() *acm.Client { diff --git a/internal/generate/awsclient/file.tmpl b/internal/generate/awsclient/file.tmpl index c6c270ac557..7f4d17457ba 100644 --- a/internal/generate/awsclient/file.tmpl +++ b/internal/generate/awsclient/file.tmpl @@ -45,8 +45,6 @@ type AWSClient struct { {{ .ProviderPackage }}Client *{{ .GoV2Package }}.{{ .ClientTypeName }} {{- end }} {{- end }} - - s3ConnURICleaningDisabled *s3.S3 } {{ range .Services }} From 053922fb6df5fb4f2c093d6edcbeec7cea51da29 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 7 Jun 2023 09:43:41 -0400 Subject: [PATCH 2/3] 'AWSClient.S3ConnURICleaningDisabled' always creates a new S3 client. --- internal/conns/awsclient.go | 9 +++++++-- internal/conns/config.go | 3 --- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/conns/awsclient.go b/internal/conns/awsclient.go index f1aaf8c8238..a590220b29b 100644 --- a/internal/conns/awsclient.go +++ b/internal/conns/awsclient.go @@ -1,9 +1,11 @@ package conns import ( + "context" "fmt" "net/http" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/apigatewayv2" "github.com/aws/aws-sdk-go/service/s3" @@ -23,8 +25,11 @@ func (client *AWSClient) RegionalHostname(prefix string) string { return fmt.Sprintf("%s.%s.%s", prefix, client.Region, client.DNSSuffix) } -func (client *AWSClient) S3ConnURICleaningDisabled() *s3.S3 { - return client.s3ConnURICleaningDisabled +func (client *AWSClient) S3ConnURICleaningDisabled(context.Context) *s3.S3 { + config := client.S3Conn().Config + config.DisableRestProtocolURICleaning = aws.Bool(true) + + return s3.New(client.Session.Copy(&config)) } // SetHTTPClient sets the http.Client used for AWS API calls. diff --git a/internal/conns/config.go b/internal/conns/config.go index 2f45f62fc34..091f732ec74 100644 --- a/internal/conns/config.go +++ b/internal/conns/config.go @@ -218,9 +218,6 @@ func (c *Config) ConfigureProvider(ctx context.Context, client *AWSClient) (*AWS } client.s3Conn = s3.New(sess.Copy(s3Config)) - s3Config.DisableRestProtocolURICleaning = aws.Bool(true) - client.s3ConnURICleaningDisabled = s3.New(sess.Copy(s3Config)) - // "Global" services that require customizations. globalAcceleratorConfig := &aws.Config{ Endpoint: aws.String(c.Endpoints[names.GlobalAccelerator]), From f9f81083df3b5d3f47fbbac6f6f5f8c597faff51 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 7 Jun 2023 09:47:43 -0400 Subject: [PATCH 3/3] Add 'context.Context' to 'AWSClient.S3ConnURICleaningDisabled()'. --- internal/service/s3/bucket.go | 2 +- internal/service/s3/bucket_test.go | 2 +- internal/service/s3/sweep.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/s3/bucket.go b/internal/service/s3/bucket.go index 87268b83ea0..e54a37ca2a9 100644 --- a/internal/service/s3/bucket.go +++ b/internal/service/s3/bucket.go @@ -1377,7 +1377,7 @@ func resourceBucketDelete(ctx context.Context, d *schema.ResourceData, meta inte // Use a S3 service client that can handle multiple slashes in URIs. // While aws_s3_object resources cannot create these object // keys, other AWS services and applications using the S3 Bucket can. - conn = meta.(*conns.AWSClient).S3ConnURICleaningDisabled() + conn := meta.(*conns.AWSClient).S3ConnURICleaningDisabled(ctx) // bucket may have things delete them log.Printf("[DEBUG] S3 Bucket attempting to forceDestroy %s", err) diff --git a/internal/service/s3/bucket_test.go b/internal/service/s3/bucket_test.go index 3fcb611a6ee..33108d62737 100644 --- a/internal/service/s3/bucket_test.go +++ b/internal/service/s3/bucket_test.go @@ -2595,7 +2595,7 @@ func testAccCheckBucketExistsWithProvider(ctx context.Context, n string, provide func testAccCheckBucketAddObjects(ctx context.Context, n string, keys ...string) resource.TestCheckFunc { return func(s *terraform.State) error { rs := s.RootModule().Resources[n] - conn := acctest.Provider.Meta().(*conns.AWSClient).S3ConnURICleaningDisabled() + conn := acctest.Provider.Meta().(*conns.AWSClient).S3ConnURICleaningDisabled(ctx) for _, key := range keys { _, err := conn.PutObjectWithContext(ctx, &s3.PutObjectInput{ diff --git a/internal/service/s3/sweep.go b/internal/service/s3/sweep.go index a0ffb726a57..89c0a64a55d 100644 --- a/internal/service/s3/sweep.go +++ b/internal/service/s3/sweep.go @@ -47,7 +47,7 @@ func sweepObjects(region string) error { return fmt.Errorf("getting client: %s", err) } - conn := client.(*conns.AWSClient).S3ConnURICleaningDisabled() + conn := client.(*conns.AWSClient).S3ConnURICleaningDisabled(ctx) input := &s3.ListBucketsInput{} output, err := conn.ListBucketsWithContext(ctx, input)