config: Don't panic if config directory contains only overrides

This commit is contained in:
Lyle Franklin 2017-10-23 15:46:15 -07:00 committed by Martin Atkins
parent 8d9b44105a
commit 43dcaa1a00
3 changed files with 30 additions and 1 deletions

View File

@ -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 {

View File

@ -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

View File

@ -0,0 +1,4 @@
variable "foo" {
default = "bar"
description = "bar"
}