Merge pull request #22130 from hashicorp/appilon/prune-meta-command

[Cleanup] prune dead code from command/meta
This commit is contained in:
appilon 2019-07-18 16:35:08 -04:00 committed by GitHub
commit 15c71e8538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 116 deletions

View File

@ -20,7 +20,6 @@ import (
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/backend/local"
"github.com/hashicorp/terraform/command/format"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/configs/configload"
"github.com/hashicorp/terraform/helper/experiment"
"github.com/hashicorp/terraform/helper/wrappedstreams"
@ -407,15 +406,6 @@ func (m *Meta) extendedFlagSet(n string) *flag.FlagSet {
return f
}
// moduleStorage returns the module.Storage implementation used to store
// modules for commands.
func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.Storage {
s := module.NewStorage(filepath.Join(root, "modules"), m.Services)
s.Ui = m.Ui
s.Mode = mode
return s
}
// process will process the meta-parameters out of the arguments. This
// will potentially modify the args in-place. It will return the resulting
// slice.

View File

@ -1,18 +1,10 @@
package command
import (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"github.com/hashicorp/terraform/plans/planfile"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/tfdiags"
)
// NOTE: Temporary file until this branch is cleaned up.
@ -32,104 +24,6 @@ func (m *Meta) Input() bool {
return true
}
// Module loads the module tree for the given root path using the legacy
// configuration loader.
//
// It expects the modules to already be downloaded. This will never
// download any modules.
//
// The configuration is validated before returning, so the returned diagnostics
// may contain warnings and/or errors. If the diagnostics contains only
// warnings, the caller may treat the returned module.Tree as valid after
// presenting the warnings to the user.
func (m *Meta) Module(path string) (*module.Tree, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
mod, err := module.NewTreeModule("", path)
if err != nil {
// Check for the error where we have no config files
if errwrap.ContainsType(err, new(config.ErrNoConfigsFound)) {
return nil, nil
}
diags = diags.Append(err)
return nil, diags
}
err = mod.Load(m.moduleStorage(m.DataDir(), module.GetModeNone))
if err != nil {
diags = diags.Append(errwrap.Wrapf("Error loading modules: {{err}}", err))
return nil, diags
}
diags = diags.Append(mod.Validate())
return mod, diags
}
// Config loads the root config for the path specified, using the legacy
// configuration loader.
//
// Path may be a directory or file. The absence of configuration is not an
// error and returns a nil Config.
func (m *Meta) Config(path string) (*config.Config, error) {
// If no explicit path was given then it is okay for there to be
// no backend configuration found.
emptyOk := path == ""
// If we had no path set, it is an error. We can't initialize unset
if path == "" {
path = "."
}
// Expand the path
if !filepath.IsAbs(path) {
var err error
path, err = filepath.Abs(path)
if err != nil {
return nil, fmt.Errorf(
"Error expanding path to backend config %q: %s", path, err)
}
}
log.Printf("[DEBUG] command: loading backend config file: %s", path)
// We first need to determine if we're loading a file or a directory.
fi, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) && emptyOk {
log.Printf(
"[INFO] command: backend config not found, returning nil: %s",
path)
return nil, nil
}
return nil, err
}
var f func(string) (*config.Config, error) = config.LoadFile
if fi.IsDir() {
f = config.LoadDir
}
// Load the configuration
c, err := f(path)
if err != nil {
// Check for the error where we have no config files and return nil
// as the configuration type.
if errwrap.ContainsType(err, new(config.ErrNoConfigsFound)) {
log.Printf(
"[INFO] command: backend config not found, returning nil: %s",
path)
return nil, nil
}
return nil, err
}
return c, nil
}
// PlanFile returns a reader for the plan file at the given path.
//
// If the return value and error are both nil, the given path exists but seems