From f8836290da2d8b9ac744483b8ec488ee8ed5a785 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 14 Sep 2014 19:35:38 -0700 Subject: [PATCH] config: not directory that config was loaded from --- config/config.go | 5 +++++ config/loader.go | 3 +++ config/loader_test.go | 23 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 60cb8818a0..431807c065 100644 --- a/config/config.go +++ b/config/config.go @@ -15,6 +15,11 @@ import ( // Config is the configuration that comes from loading a collection // of Terraform templates. type Config struct { + // Dir is the path to the directory where this configuration was + // loaded from. If it is blank, this configuration wasn't loaded from + // any meaningful directory. + Dir string + Modules []*Module ProviderConfigs []*ProviderConfig Resources []*Resource diff --git a/config/loader.go b/config/loader.go index 7b3112ad6d..18d5856d62 100644 --- a/config/loader.go +++ b/config/loader.go @@ -140,6 +140,9 @@ func LoadDir(root string) (*Config, error) { } } + // Mark the directory + result.Dir = root + return result, nil } diff --git a/config/loader_test.go b/config/loader_test.go index 3dad74940f..50e792ea09 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -25,6 +25,10 @@ func TestLoadBasic(t *testing.T) { t.Fatal("config should not be nil") } + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + actual := variablesStr(c.Variables) if actual != strings.TrimSpace(basicVariablesStr) { t.Fatalf("bad:\n%s", actual) @@ -85,6 +89,10 @@ func TestLoadBasic_json(t *testing.T) { t.Fatal("config should not be nil") } + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + actual := variablesStr(c.Variables) if actual != strings.TrimSpace(basicVariablesStr) { t.Fatalf("bad:\n%s", actual) @@ -116,6 +124,10 @@ func TestLoadBasic_modules(t *testing.T) { t.Fatal("config should not be nil") } + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + actual := modulesStr(c.Modules) if actual != strings.TrimSpace(modulesModulesStr) { t.Fatalf("bad:\n%s", actual) @@ -131,6 +143,10 @@ func TestLoad_variables(t *testing.T) { t.Fatal("config should not be nil") } + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + actual := variablesStr(c.Variables) if actual != strings.TrimSpace(variablesVariablesStr) { t.Fatalf("bad:\n%s", actual) @@ -138,7 +154,8 @@ func TestLoad_variables(t *testing.T) { } func TestLoadDir_basic(t *testing.T) { - c, err := LoadDir(filepath.Join(fixtureDir, "dir-basic")) + dir := filepath.Join(fixtureDir, "dir-basic") + c, err := LoadDir(dir) if err != nil { t.Fatalf("err: %s", err) } @@ -147,6 +164,10 @@ func TestLoadDir_basic(t *testing.T) { t.Fatal("config should not be nil") } + if c.Dir != dir { + t.Fatalf("bad: %#v", c.Dir) + } + actual := variablesStr(c.Variables) if actual != strings.TrimSpace(dirBasicVariablesStr) { t.Fatalf("bad:\n%s", actual)