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

fix: dont fail stack list if terramate block is absent #102

Merged
merged 1 commit into from
Dec 20, 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
10 changes: 6 additions & 4 deletions metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestLoadMetadata(t *testing.T) {
wantErr error
}

const invalidHCL = "block {"

tcases := []testcase{
{
name: "no stacks",
Expand Down Expand Up @@ -113,17 +115,17 @@ func TestLoadMetadata(t *testing.T) {
{
name: "single invalid stack",
layout: []string{
fmt.Sprintf("f:invalid-stack/%s:data=notvalidhcl", config.Filename),
fmt.Sprintf("f:invalid-stack/%s:data=%s", config.Filename, invalidHCL),
},
wantErr: hcl.ErrNoTerramateBlock,
wantErr: hcl.ErrHCLSyntax,
},
{
name: "valid stack with invalid stack",
layout: []string{
"s:stack-valid-1",
fmt.Sprintf("f:invalid-stack/%s:data=notvalidhcl", config.Filename),
fmt.Sprintf("f:invalid-stack/%s:data=%s", config.Filename, invalidHCL),
},
wantErr: hcl.ErrNoTerramateBlock,
wantErr: hcl.ErrHCLSyntax,
},
}

Expand Down
7 changes: 7 additions & 0 deletions stack/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package stack

import (
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -88,6 +89,12 @@ func (l Loader) TryLoad(dir string) (stack S, found bool, err error) {
}
fname := filepath.Join(dir, config.Filename)
cfg, err := hcl.ParseFile(fname)

if errors.Is(err, hcl.ErrNoTerramateBlock) {
// Config blocks may have only globals, no terramate
return S{}, false, nil
}

if err != nil {
return S{}, false, err
}
Expand Down