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

chore: remove duplicated stack listing #120

Merged
merged 1 commit into from
Dec 30, 2021
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
16 changes: 3 additions & 13 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,20 @@ func Do(root string) error {
return fmt.Errorf("project's root %q is not a directory", root)
}

stackEntries, err := terramate.ListStacks(root)
if err != nil {
return fmt.Errorf("listing stack: %w", err)
}

metadata, err := terramate.LoadMetadata(root)
if err != nil {
return fmt.Errorf("loading metadata: %v", err)
return fmt.Errorf("loading metadata: %w", err)
}

var errs []error

for _, entry := range stackEntries {
for _, stackMetadata := range metadata.Stacks {
// At the time the most intuitive way was to start from the stack
// and go up until reaching the root, looking for a config.
// Basically navigating from the order of precedence, since
// more specific configuration overrides base configuration.
// Not the most optimized way (re-parsing), we can improve later
stackpath := project.AbsPath(root, entry.Stack.Dir)
stackMetadata, ok := metadata.StackMetadata(stackpath)
if !ok {
errs = append(errs, fmt.Errorf("stack %q: no metadata found", stackpath))
continue
}
stackpath := project.AbsPath(root, stackMetadata.Path)

globals, err := terramate.LoadStackGlobals(root, stackMetadata)
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ func LoadMetadata(basedir string) (Metadata, error) {
}, nil
}

// StackMetadata gets the metadata of a specific stack given its absolute path.
func (m Metadata) StackMetadata(abspath string) (StackMetadata, bool) {
path := strings.TrimPrefix(abspath, m.basedir)
for _, stackMetadata := range m.Stacks {
if stackMetadata.Path == path {
return stackMetadata, true
}
}
return StackMetadata{}, false
}

// SetOnEvalCtx will add the proper namespace for evaluation of stack metadata
// on the given evaluation context.
func (m StackMetadata) SetOnEvalCtx(evalctx *eval.Context) error {
Expand Down