Skip to content

Commit

Permalink
Add metadata.component and metadata.inherits
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh committed Jan 12, 2022
1 parent a2cf204 commit 66e0d9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -32,7 +32,7 @@ components:
# 3. `mixin-2` overrides `mixin-1` and its base components (all the way up its inheritance chain).
# 4. This `test/test-component-override-3` overrides `mixin-2` and its base components (all the way up its inheritance chain).
# Inheritance: test/test-component-override-3 -> mixin-2 -> mixin-1 -> test/test-component-override-2 -> test/test-component-override -> test/test-component
inherit:
inherits:
- "test/test-component-override"
- "test/test-component-override-2"
- "mixin-1"
Expand Down
6 changes: 3 additions & 3 deletions pkg/stack/stack_processor.go
Expand Up @@ -447,21 +447,21 @@ func ProcessConfig(
// It uses a method similar to Method Resolution Order (MRO), which is how Python supports multiple inheritance.
//
// In the case of multiple base components, it is processed left to right, in the order by which it was declared.
// For example: `metadata.inherit: [componentA, componentB]`
// For example: `metadata.inherits: [componentA, componentB]`
// will deep-merge all the base components of `componentA` (each component overriding its base),
// then all the base components of `componentB` (each component overriding its base),
// then the two results are deep-merged together (`componentB` inheritance chain will override values from `componentA' inheritance chain).
if baseComponentFromMetadata, baseComponentFromMetadataExist := componentMetadata["component"].(string); baseComponentFromMetadataExist {
baseComponentName = baseComponentFromMetadata
}

if inheritList, inheritListExist := componentMetadata["inherit"].([]interface{}); inheritListExist {
if inheritList, inheritListExist := componentMetadata["inherits"].([]interface{}); inheritListExist {
for _, v := range inheritList {
base := v.(string)

if _, ok2 := allTerraformComponentsMap[base]; !ok2 {
errorMessage := fmt.Sprintf("The component '%[1]s' in the stack '%[2]s' inherits from '%[3]s' "+
"(using 'metadata.inherit'), but '%[3]s' does not exist in the stack '%[2]s'",
"(using 'metadata.inherits'), but '%[3]s' does not exist in the stack '%[2]s'",
component,
stackName,
base,
Expand Down

0 comments on commit 66e0d9c

Please sign in to comment.