Skip to content

Commit

Permalink
Fix bucket region configuration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Dec 25, 2023
1 parent 24f9805 commit d19f224
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tfstate/remote_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ func readS3(ctx context.Context, bucket, key string, opt s3Option) (io.ReadClose
if err != nil {
return nil, err
}
if opt.region == "" {
opt.region, err = getBucketRegion(ctx, cfg, bucket)
region, err := getBucketRegion(ctx, cfg, bucket)
if err != nil {
return nil, err
}
if region != opt.region {
// reload config with bucket region
cfg, err = config.LoadDefaultConfig(ctx,
config.WithRegion(region),
)
if err != nil {
return nil, err
}
}

if opt.role_arn != "" {
arn, err := arn.Parse(opt.role_arn)
if err != nil {
Expand Down

0 comments on commit d19f224

Please sign in to comment.