From 40e593ddc11150034ff5927ab118eb8d5f966d31 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Mon, 8 Jan 2024 14:37:29 -0800 Subject: [PATCH] Adds constant for default workspace prefix --- internal/backend/remote-state/s3/backend.go | 2 +- internal/backend/remote-state/s3/backend_state.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/backend/remote-state/s3/backend.go b/internal/backend/remote-state/s3/backend.go index 7a67ea2a50..823385b9a8 100644 --- a/internal/backend/remote-state/s3/backend.go +++ b/internal/backend/remote-state/s3/backend.go @@ -942,7 +942,7 @@ func (b *Backend) Configure(obj cty.Value) tfdiags.Diagnostics { ) b.acl = stringAttr(obj, "acl") - b.workspaceKeyPrefix = stringAttrDefault(obj, "workspace_key_prefix", "env:") + b.workspaceKeyPrefix = stringAttrDefault(obj, "workspace_key_prefix", defaultWorkspaceKeyPrefix) b.serverSideEncryption = boolAttr(obj, "encrypt") b.kmsKeyID = stringAttr(obj, "kms_key_id") b.ddbTable = stringAttr(obj, "dynamodb_table") diff --git a/internal/backend/remote-state/s3/backend_state.go b/internal/backend/remote-state/s3/backend_state.go index 217acf0f80..12ff6b88a9 100644 --- a/internal/backend/remote-state/s3/backend_state.go +++ b/internal/backend/remote-state/s3/backend_state.go @@ -22,6 +22,12 @@ import ( "github.com/hashicorp/terraform/internal/states/statemgr" ) +const ( + // defaultWorkspaceKeyPrefix is the default prefix for workspace storage. + // The colon is used to reduce the chance of name conflicts with existing objects. + defaultWorkspaceKeyPrefix = "env:" +) + func (b *Backend) Workspaces() ([]string, error) { const maxKeys = 1000