ignore AccessDenied error on listing workspaces in S3 (#1445)

Signed-off-by: ollevche <ollevche@gmail.com>
This commit is contained in:
Oleksandr Levchenkov 2024-03-29 14:08:34 +02:00 committed by GitHub
parent 969a7e0a99
commit 02e12d054e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

2
go.mod
View File

@ -22,6 +22,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.5
github.com/aws/aws-sdk-go-v2/service/kms v1.26.5
github.com/aws/aws-sdk-go-v2/service/s3 v1.46.0
github.com/aws/smithy-go v1.17.0
github.com/bgentry/speakeasy v0.1.0
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/chzyer/readline v1.5.1
@ -154,7 +155,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.6 // indirect
github.com/aws/smithy-go v1.17.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bradleyfalzon/ghinstallation/v2 v2.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect

View File

@ -16,6 +16,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/states"
@ -48,11 +49,18 @@ func (b *Backend) Workspaces() ([]string, error) {
for pg.HasMorePages() {
page, err := pg.NextPage(ctx)
if err != nil {
var e *types.NoSuchBucket
if errors.As(err, &e) {
var noBucketErr *types.NoSuchBucket
if errors.As(err, &noBucketErr) {
return nil, fmt.Errorf(errS3NoSuchBucket, err)
}
// Ignoring AccessDenied errors for backward compatibility,
// since it should work for default state when no other workspaces present.
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "AccessDenied" {
break
}
return nil, err
}