Skip to content

Commit 7cb356d

Browse files
authored
Add component attribute to the outputs of Terraform components that have a base component (#16)
1 parent 9157dcd commit 7cb356d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

examples/data-sources/utils_stack_config_yaml/data-source.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ output "uw2_uat_aurora_postgres_vars" {
5252
output "uw2_uat_aurora_postgres_2_vars" {
5353
value = local.result[3]["components"]["terraform"]["aurora-postgres-2"]["vars"]
5454
}
55+
56+
output "uw2_uat_aurora_postgres_2_component" {
57+
value = local.result[3]["components"]["terraform"]["aurora-postgres-2"]["component"]
58+
}

internal/stack/stack_processor.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,17 @@ func ProcessConfig(stack string, config map[interface{}]interface{}) (map[interf
125125

126126
baseComponentVars := map[interface{}]interface{}{}
127127
baseComponentBackend := map[interface{}]interface{}{}
128+
baseComponentName := ""
128129

129-
if baseComponentName, ok2 := componentMap["component"]; ok2 {
130-
baseComponent := baseComponentName.(string)
130+
if baseComponent, ok2 := componentMap["component"]; ok2 {
131+
baseComponentName = baseComponent.(string)
131132

132-
if baseComponentMap, ok3 := allTerraformComponents[baseComponent].(map[interface{}]interface{}); ok3 {
133+
if baseComponentMap, ok3 := allTerraformComponents[baseComponentName].(map[interface{}]interface{}); ok3 {
133134
baseComponentVars = baseComponentMap["vars"].(map[interface{}]interface{})
134135
baseComponentBackend = baseComponentMap["backend"].(map[interface{}]interface{})[backendType].(map[interface{}]interface{})
135136
} else {
136137
return nil, errors.New("Terraform component '" + component.(string) + "' defines attribute 'component: " +
137-
baseComponent + "', " + "but `" + baseComponent + "' is not defined in the stack '" + stack + "'")
138+
baseComponentName + "', " + "but `" + baseComponentName + "' is not defined in the stack '" + stack + "'")
138139
}
139140
}
140141

@@ -152,6 +153,11 @@ func ProcessConfig(stack string, config map[interface{}]interface{}) (map[interf
152153
comp["vars"] = finalComponentVars
153154
comp["backend_type"] = backendType
154155
comp["backend"] = finalComponentBackend
156+
157+
if baseComponentName != "" {
158+
comp["component"] = baseComponentName
159+
}
160+
155161
terraformComponents[component] = comp
156162
}
157163
}

0 commit comments

Comments
 (0)