From d19f2244c936b0ef85e6b064b787dd3c2e62da0e Mon Sep 17 00:00:00 2001 From: fujiwara Date: Mon, 25 Dec 2023 09:32:05 +0900 Subject: [PATCH] Fix bucket region configuration issue --- tfstate/remote_s3.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tfstate/remote_s3.go b/tfstate/remote_s3.go index a5f7c7a..53f93d6 100644 --- a/tfstate/remote_s3.go +++ b/tfstate/remote_s3.go @@ -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 {