From 0889c118a87951b91a514d6bfb45e86dfdad97af Mon Sep 17 00:00:00 2001 From: rv-jmaggio Date: Fri, 15 Dec 2017 17:50:36 -0500 Subject: [PATCH] Fixing issues with workspace_key_prefix --- backend/remote-state/s3/backend_state.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/remote-state/s3/backend_state.go b/backend/remote-state/s3/backend_state.go index f38b199b04..25b68d9617 100644 --- a/backend/remote-state/s3/backend_state.go +++ b/backend/remote-state/s3/backend_state.go @@ -39,9 +39,13 @@ func (b *Backend) States() ([]string, error) { // extract the env name from the S3 key func (b *Backend) keyEnv(key string) string { - // we have 3 parts, the prefix, the env name, and the key name - parts := strings.SplitN(key, "/", 3) - if len(parts) < 3 { + if b.workspaceKeyPrefix == "" { + parts := strings.Split(key, "/") + return parts[0] + } + parts := strings.SplitAfter(key, b.workspaceKeyPrefix) + + if len(parts) < 2 { // no env here return "" } @@ -51,6 +55,12 @@ func (b *Backend) keyEnv(key string) string { return "" } + parts = strings.Split(parts[1], "/") + + if len(parts) < 3 { + return "" + } + // not our key, so don't include it in our listing if parts[2] != b.keyName { return ""