From 3c9a92e04adef097b6f365d5d09a4cd133db8ca4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 May 2016 10:46:34 -0700 Subject: [PATCH] command: Context buliding allows empty module trees --- command/meta.go | 11 ++++++++--- config/module/tree.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/command/meta.go b/command/meta.go index 092b37dd5..f54fca13d 100644 --- a/command/meta.go +++ b/command/meta.go @@ -146,9 +146,14 @@ func (m *Meta) Context(copts contextOpts) (*terraform.Context, bool, error) { } // Load the root module - mod, err := module.NewTreeModule("", copts.Path) - if err != nil { - return nil, false, fmt.Errorf("Error loading config: %s", err) + var mod *module.Tree + if copts.Path != "" { + mod, err = module.NewTreeModule("", copts.Path) + if err != nil { + return nil, false, fmt.Errorf("Error loading config: %s", err) + } + } else { + mod = module.NewEmptyTree() } err = mod.Load(m.moduleStorage(m.DataDir()), copts.GetMode) diff --git a/config/module/tree.go b/config/module/tree.go index 417ddcca3..6e7d8b0ea 100644 --- a/config/module/tree.go +++ b/config/module/tree.go @@ -33,6 +33,11 @@ func NewTree(name string, c *config.Config) *Tree { return &Tree{config: c, name: name} } +// NewEmptyTree returns a new tree that is empty (contains no configuration). +func NewEmptyTree() *Tree { + return &Tree{config: &config.Config{}} +} + // NewTreeModule is like NewTree except it parses the configuration in // the directory and gives it a specific name. Use a blank name "" to specify // the root module.