Skip to content

Commit 7a01e78

Browse files
committed
config: LoadDir with no matching files errors
1 parent 6bf543c commit 7a01e78

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎config/loader.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"fmt"
45
"path/filepath"
56
)
67

@@ -35,6 +36,12 @@ func LoadDir(path string) (*Config, error) {
3536
return nil, err
3637
}
3738

39+
if len(matches) == 0 {
40+
return nil, fmt.Errorf(
41+
"No Terraform configuration files found in directory: %s",
42+
path)
43+
}
44+
3845
var result *Config
3946
for _, f := range matches {
4047
c, err := Load(f)

‎config/loader_test.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ func TestLoadDir_basic(t *testing.T) {
128128
}
129129
}
130130

131+
func TestLoadDir_noConfigs(t *testing.T) {
132+
_, err := LoadDir(filepath.Join(fixtureDir, "dir-empty"))
133+
if err == nil {
134+
t.Fatal("should error")
135+
}
136+
}
137+
131138
func outputsStr(os map[string]*Output) string {
132139
ns := make([]string, 0, len(os))
133140
for n, _ := range os {

‎config/test-fixtures/dir-empty/.gitkeep‎

Whitespace-only changes.

0 commit comments

Comments
 (0)