Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: Choose correct region for S3 (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbernays authored Jul 13, 2022
1 parent 6441700 commit e75f91b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions resources/services/s3/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,25 @@ func Buckets() *schema.Table {
// Table Resolver Functions
// ====================================================================================================================

// listBucketRegion identifies the canonical region for S3 based on the partition
// in the future we might want to make this configurable if users are alright with the fact that performing this
// action in different regions will return different results
func listBucketRegion(cl *client.Client) string {
switch cl.Partition {
case "aws-cn":
return "cn-north-1"
case "aws-us-gov":
return "us-gov-west-1"
default:
return "us-east-1"
}
}

func fetchS3Buckets(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- interface{}) error {
svc := meta.(*client.Client).Services().S3
cl := meta.(*client.Client)
svc := cl.Services().S3
response, err := svc.ListBuckets(ctx, nil, func(options *s3.Options) {
options.Region = "us-east-1"
options.Region = listBucketRegion(cl)
})
if err != nil {
return diag.WrapError(err)
Expand Down

0 comments on commit e75f91b

Please sign in to comment.