Skip to content

Commit

Permalink
Use the current credentials when trying to get the bucket region
Browse files Browse the repository at this point in the history
This fixes hashicorp#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
Ergin Babani committed Oct 5, 2020
1 parent fd656dd commit 7fffddf
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,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 7fffddf

Please sign in to comment.