Skip to content

Commit

Permalink
include some protection on the azurerm backend when global does not e…
Browse files Browse the repository at this point in the history
…xist (#548)
  • Loading branch information
aochsner committed Feb 29, 2024
1 parent d040264 commit 08dac04
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/stack/stack_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")

}
}
Expand Down

0 comments on commit 08dac04

Please sign in to comment.