Skip to content

Commit

Permalink
service/s3: Use the current credentials when trying to get the bucket…
Browse files Browse the repository at this point in the history
… region (#15481)

This fixes #15420 where in aws-cn using anonymous credentials will cause the Head request to return Unauthorized. That error in turn fill cause terraform bucket operations to fail.
  • Loading branch information
ebabani committed Nov 17, 2020
1 parent 27353a2 commit 17429ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions aws/data_source_aws_s3_bucket.go
Expand Up @@ -100,6 +100,12 @@ func bucketLocation(client *AWSClient, d *schema.ResourceData, bucket string) er
// the provider s3_force_path_style configuration, which defaults to
// false, but allows override.
r.Config.S3ForcePathStyle = client.s3conn.Config.S3ForcePathStyle

// By default, GetBucketRegion uses anonymous credentials when doing
// a HEAD request to get the bucket region. This breaks in aws-cn regions
// when the account doesn't have an ICP license to host public content.
// Use the current credentials when getting the bucket region.
r.Config.Credentials = client.s3conn.Config.Credentials
})
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions aws/resource_aws_s3_bucket.go
Expand Up @@ -1263,6 +1263,12 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
// the provider s3_force_path_style configuration, which defaults to
// false, but allows override.
r.Config.S3ForcePathStyle = s3conn.Config.S3ForcePathStyle

// By default, GetBucketRegion uses anonymous credentials when doing
// a HEAD request to get the bucket region. This breaks in aws-cn regions
// when the account doesn't have an ICP license to host public content.
// Use the current credentials when getting the bucket region.
r.Config.Credentials = s3conn.Config.Credentials
})
})
if err != nil {
Expand Down

0 comments on commit 17429ae

Please sign in to comment.