Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude abstract components from list #851

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading