Skip to content

Commit

Permalink
Exclude abstract components from list (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya and aknysh authored Dec 14, 2024
1 parent 5681e54 commit ed93da1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/exec/atmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions internal/exec/describe_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit ed93da1

Please sign in to comment.