diff --git a/internal/exec/atmos.go b/internal/exec/atmos.go index 446c42ca1..a7f5f6f7d 100644 --- a/internal/exec/atmos.go +++ b/internal/exec/atmos.go @@ -51,7 +51,7 @@ func ExecuteAtmosCmd() error { if v2, ok := v.(map[string]any); ok { if v3, ok := v2["components"].(map[string]any); ok { if v4, ok := v3["terraform"].(map[string]any); ok { - return k, lo.Keys(v4) + return k, FilterAbstractComponents(v4) } // TODO: process 'helmfile' components and stacks. // This will require checking the list of commands and filtering the stacks and components depending on the selected command. diff --git a/internal/exec/describe_component.go b/internal/exec/describe_component.go index 2fabc2611..5afea0dd7 100644 --- a/internal/exec/describe_component.go +++ b/internal/exec/describe_component.go @@ -2,6 +2,7 @@ package exec import ( "github.com/pkg/errors" + "github.com/samber/lo" "github.com/spf13/cobra" cfg "github.com/cloudposse/atmos/pkg/config" @@ -83,3 +84,32 @@ func ExecuteDescribeComponent( return configAndStacksInfo.ComponentSection, nil } + +// FilterAbstractComponents This function removes abstract components and returns the list of components +func FilterAbstractComponents(componentsMap map[string]any) []string { + if componentsMap == nil { + return []string{} + } + components := make([]string, 0) + for _, k := range lo.Keys(componentsMap) { + componentMap, ok := componentsMap[k].(map[string]any) + if !ok { + components = append(components, k) + continue + } + + metadata, ok := componentMap["metadata"].(map[string]any) + if !ok { + components = append(components, k) + continue + } + if componentType, ok := metadata["type"].(string); ok && componentType == "abstract" { + continue + } + if componentEnabled, ok := metadata["enabled"].(bool); ok && !componentEnabled { + continue + } + components = append(components, k) + } + return components +}