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
2 changed files with 11 additions and 3 deletions

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
}