command: Context buliding allows empty module trees

This commit is contained in:
Mitchell Hashimoto 2016-05-04 10:46:34 -07:00
parent 182a8a28c0
commit 3c9a92e04a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 13 additions and 3 deletions

View File

@ -146,9 +146,14 @@ func (m *Meta) Context(copts contextOpts) (*terraform.Context, bool, error) {
} }
// Load the root module // Load the root module
mod, err := module.NewTreeModule("", copts.Path) var mod *module.Tree
if err != nil { if copts.Path != "" {
return nil, false, fmt.Errorf("Error loading config: %s", err) 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) err = mod.Load(m.moduleStorage(m.DataDir()), copts.GetMode)

View File

@ -33,6 +33,11 @@ func NewTree(name string, c *config.Config) *Tree {
return &Tree{config: c, name: name} 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 // 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 directory and gives it a specific name. Use a blank name "" to specify
// the root module. // the root module.