diff --git a/config/loader.go b/config/loader.go index 750e9d15d..a8cbb5adf 100644 --- a/config/loader.go +++ b/config/loader.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "path/filepath" ) @@ -35,6 +36,12 @@ func LoadDir(path string) (*Config, error) { return nil, err } + if len(matches) == 0 { + return nil, fmt.Errorf( + "No Terraform configuration files found in directory: %s", + path) + } + var result *Config for _, f := range matches { c, err := Load(f) diff --git a/config/loader_test.go b/config/loader_test.go index 2737ab38b..4181dcb34 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -128,6 +128,13 @@ func TestLoadDir_basic(t *testing.T) { } } +func TestLoadDir_noConfigs(t *testing.T) { + _, err := LoadDir(filepath.Join(fixtureDir, "dir-empty")) + if err == nil { + t.Fatal("should error") + } +} + func outputsStr(os map[string]*Output) string { ns := make([]string, 0, len(os)) for n, _ := range os { diff --git a/config/test-fixtures/dir-empty/.gitkeep b/config/test-fixtures/dir-empty/.gitkeep new file mode 100644 index 000000000..e69de29bb