diff --git a/config/loader.go b/config/loader.go index da74e9762..740d0ec5f 100644 --- a/config/loader.go +++ b/config/loader.go @@ -103,6 +103,10 @@ func LoadDir(root string) (*Config, error) { // IsEmptyDir returns true if the directory given has no Terraform // configuration files. func IsEmptyDir(root string) (bool, error) { + if _, err := os.Stat(root); err != nil && os.IsNotExist(err) { + return true, nil + } + fs, os, err := dirFiles(root) if err != nil { return false, err diff --git a/config/loader_test.go b/config/loader_test.go index da4a2dd8f..70dba0a16 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -16,6 +16,16 @@ func TestIsEmptyDir(t *testing.T) { } } +func TestIsEmptyDir_noExist(t *testing.T) { + val, err := IsEmptyDir(filepath.Join(fixtureDir, "nopenopenope")) + if err != nil { + t.Fatalf("err: %s", err) + } + if !val { + t.Fatal("should be empty") + } +} + func TestIsEmptyDir_noConfigs(t *testing.T) { val, err := IsEmptyDir(filepath.Join(fixtureDir, "dir-empty")) if err != nil {