Merge pull request #22130 from hashicorp/appilon/prune-meta-command
[Cleanup] prune dead code from command/meta
This commit is contained in:
commit
15c71e8538
|
@ -20,7 +20,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/backend"
|
"github.com/hashicorp/terraform/backend"
|
||||||
"github.com/hashicorp/terraform/backend/local"
|
"github.com/hashicorp/terraform/backend/local"
|
||||||
"github.com/hashicorp/terraform/command/format"
|
"github.com/hashicorp/terraform/command/format"
|
||||||
"github.com/hashicorp/terraform/config/module"
|
|
||||||
"github.com/hashicorp/terraform/configs/configload"
|
"github.com/hashicorp/terraform/configs/configload"
|
||||||
"github.com/hashicorp/terraform/helper/experiment"
|
"github.com/hashicorp/terraform/helper/experiment"
|
||||||
"github.com/hashicorp/terraform/helper/wrappedstreams"
|
"github.com/hashicorp/terraform/helper/wrappedstreams"
|
||||||
|
@ -407,15 +406,6 @@ func (m *Meta) extendedFlagSet(n string) *flag.FlagSet {
|
||||||
return f
|
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
|
// process will process the meta-parameters out of the arguments. This
|
||||||
// will potentially modify the args in-place. It will return the resulting
|
// will potentially modify the args in-place. It will return the resulting
|
||||||
// slice.
|
// slice.
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/plans/planfile"
|
"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.
|
// NOTE: Temporary file until this branch is cleaned up.
|
||||||
|
@ -32,104 +24,6 @@ func (m *Meta) Input() bool {
|
||||||
return true
|
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.
|
// 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
|
// If the return value and error are both nil, the given path exists but seems
|
||||||
|
|
Loading…
Reference in New Issue