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

fix: Choose correct region for S3 #1216

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Changes from all commits
Commits
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
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