|
|
|
|
@ -15,6 +15,7 @@ import (
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
|
|
|
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
|
|
|
|
|
|
|
|
|
|
baselogging "github.com/hashicorp/aws-sdk-go-base/v2/logging"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/backend"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/states"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/states/remote"
|
|
|
|
|
@ -25,6 +26,11 @@ func (b *Backend) Workspaces() ([]string, error) {
|
|
|
|
|
const maxKeys = 1000
|
|
|
|
|
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
log := logger()
|
|
|
|
|
log = logWithOperation(log, operationBackendWorkspaces)
|
|
|
|
|
log = log.With(
|
|
|
|
|
logKeyBucket, b.bucketName,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
prefix := ""
|
|
|
|
|
|
|
|
|
|
@ -32,6 +38,10 @@ func (b *Backend) Workspaces() ([]string, error) {
|
|
|
|
|
prefix = b.workspaceKeyPrefix + "/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log = log.With(
|
|
|
|
|
logKeyBackendWorkspacePrefix, prefix,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
params := &s3.ListObjectsV2Input{
|
|
|
|
|
Bucket: aws.String(b.bucketName),
|
|
|
|
|
Prefix: aws.String(prefix),
|
|
|
|
|
@ -40,6 +50,9 @@ func (b *Backend) Workspaces() ([]string, error) {
|
|
|
|
|
|
|
|
|
|
wss := []string{backend.DefaultStateName}
|
|
|
|
|
|
|
|
|
|
ctx, baselog := baselogging.NewHcLogger(ctx, log)
|
|
|
|
|
ctx = baselogging.RegisterLogger(ctx, baselog)
|
|
|
|
|
|
|
|
|
|
pages := s3.NewListObjectsV2Paginator(b.s3Client, params)
|
|
|
|
|
for pages.HasMorePages() {
|
|
|
|
|
page, err := pages.NextPage(ctx)
|
|
|
|
|
@ -102,10 +115,18 @@ func (b *Backend) keyEnv(key string) string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Backend) DeleteWorkspace(name string, _ bool) error {
|
|
|
|
|
log := logger()
|
|
|
|
|
log = logWithOperation(log, operationBackendDeleteWorkspace)
|
|
|
|
|
log = log.With(
|
|
|
|
|
logKeyBackendWorkspace, name,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if name == backend.DefaultStateName || name == "" {
|
|
|
|
|
return fmt.Errorf("can't delete default state")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Info("Deleting workspace")
|
|
|
|
|
|
|
|
|
|
client, err := b.remoteClient(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
|