From 08dac04b9240bb13d771e8d3ce3f17d02ae6eec2 Mon Sep 17 00:00:00 2001 From: Andrew Ochsner Date: Thu, 29 Feb 2024 09:38:28 -0600 Subject: [PATCH] include some protection on the azurerm backend when global does not exist (#548) --- pkg/stack/stack_processor.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/stack/stack_processor.go b/pkg/stack/stack_processor.go index f73d989eb..a0a8f5cdb 100644 --- a/pkg/stack/stack_processor.go +++ b/pkg/stack/stack_processor.go @@ -1002,15 +1002,18 @@ func ProcessStackConfig( if componentAzurerm, componentAzurermExists := componentBackendSection["azurerm"].(map[any]any); !componentAzurermExists { if _, componentAzurermKeyExists := componentAzurerm["key"].(string); !componentAzurermKeyExists { azureKeyPrefixComponent := component - baseKeyName := "" + var keyName []string if baseComponentName != "" { azureKeyPrefixComponent = baseComponentName } if globalAzurerm, globalAzurermExists := globalBackendSection["azurerm"].(map[any]any); globalAzurermExists { - baseKeyName = globalAzurerm["key"].(string) + if _, globalAzurermKeyExists := globalAzurerm["key"].(string); globalAzurermKeyExists { + keyName = append(keyName, globalAzurerm["key"].(string)) + } } componentKeyName := strings.Replace(azureKeyPrefixComponent, "/", "-", -1) - finalComponentBackend["key"] = fmt.Sprintf("%s/%s.terraform.tfstate", baseKeyName, componentKeyName) + keyName = append(keyName, fmt.Sprintf("%s.terraform.tfstate", componentKeyName)) + finalComponentBackend["key"] = strings.Join(keyName, "/") } }