diff --git a/config/loader.go b/config/loader.go index 5dd7d4689..6e3478167 100644 --- a/config/loader.go +++ b/config/loader.go @@ -80,7 +80,7 @@ func LoadDir(root string) (*Config, error) { if err != nil { return nil, err } - if len(files) == 0 { + if len(files) == 0 && len(overrides) == 0 { return nil, &ErrNoConfigsFound{Dir: root} } @@ -112,6 +112,9 @@ func LoadDir(root string) (*Config, error) { result = c } } + if len(files) == 0 { + result = &Config{} + } // Load all the overrides, and merge them into the config for _, f := range overrides { diff --git a/config/loader_test.go b/config/loader_test.go index b9dca782a..0bc3b8b55 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -1022,6 +1022,22 @@ func TestLoad_jsonAttributes(t *testing.T) { } } +func TestLoad_onlyOverride(t *testing.T) { + c, err := LoadDir(filepath.Join(fixtureDir, "dir-only-override")) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + actual := variablesStr(c.Variables) + if actual != strings.TrimSpace(dirOnlyOverrideVariablesStr) { + t.Fatalf("bad:\n%s", actual) + } +} + const jsonAttributeStr = ` cloudstack_firewall.test (x1) ipaddress @@ -1229,6 +1245,12 @@ foo bar ` +const dirOnlyOverrideVariablesStr = ` +foo + bar + bar +` + const importProvidersStr = ` aws bar diff --git a/config/test-fixtures/dir-only-override/main_override.tf b/config/test-fixtures/dir-only-override/main_override.tf new file mode 100644 index 000000000..f902801bd --- /dev/null +++ b/config/test-fixtures/dir-only-override/main_override.tf @@ -0,0 +1,4 @@ +variable "foo" { + default = "bar" + description = "bar" +}