2014-07-01 12:02:13 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-01-18 22:50:45 -06:00
|
|
|
"os"
|
2017-06-16 13:09:47 -05:00
|
|
|
"runtime"
|
2014-07-01 12:02:13 -05:00
|
|
|
)
|
|
|
|
|
2014-09-29 13:24:16 -05:00
|
|
|
// Set to true when we're testing
|
|
|
|
var test bool = false
|
|
|
|
|
2015-02-21 18:04:32 -06:00
|
|
|
// DefaultDataDir is the default directory for storing local data.
|
|
|
|
const DefaultDataDir = ".terraform"
|
|
|
|
|
2017-06-15 13:26:12 -05:00
|
|
|
// PluginPathFile is the name of the file in the data dir which stores the list
|
|
|
|
// of directories supplied by the user with the `-plugin-dir` flag during init.
|
|
|
|
const PluginPathFile = "plugin_path"
|
|
|
|
|
2017-06-16 13:09:47 -05:00
|
|
|
// pluginMachineName is the directory name used in new plugin paths.
|
|
|
|
const pluginMachineName = runtime.GOOS + "_" + runtime.GOARCH
|
|
|
|
|
2017-06-15 09:12:00 -05:00
|
|
|
// DefaultPluginVendorDir is the location in the config directory to look for
|
|
|
|
// user-added plugin binaries. Terraform only reads from this path if it
|
|
|
|
// exists, it is never created by terraform.
|
2017-06-16 13:09:47 -05:00
|
|
|
const DefaultPluginVendorDir = "terraform.d/plugins/" + pluginMachineName
|
2017-06-15 09:12:00 -05:00
|
|
|
|
2014-07-11 23:03:56 -05:00
|
|
|
// DefaultStateFilename is the default filename used for the state file.
|
|
|
|
const DefaultStateFilename = "terraform.tfstate"
|
|
|
|
|
2014-08-05 11:32:01 -05:00
|
|
|
// DefaultVarsFilename is the default filename used for vars
|
|
|
|
const DefaultVarsFilename = "terraform.tfvars"
|
|
|
|
|
2015-09-11 13:56:20 -05:00
|
|
|
// DefaultBackupExtension is added to the state file to form the path
|
|
|
|
const DefaultBackupExtension = ".backup"
|
2014-07-27 17:09:04 -05:00
|
|
|
|
2015-10-05 15:06:08 -05:00
|
|
|
// DefaultParallelism is the limit Terraform places on total parallel
|
|
|
|
// operations as it walks the dependency graph.
|
|
|
|
const DefaultParallelism = 10
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// ErrUnsupportedLocalOp is the common error message shown for operations
|
|
|
|
// that require a backend.Local.
|
|
|
|
const ErrUnsupportedLocalOp = `The configured backend doesn't support this operation.
|
|
|
|
|
|
|
|
The "backend" in Terraform defines how Terraform operates. The default
|
|
|
|
backend performs all operations locally on your machine. Your configuration
|
|
|
|
is configured to use a non-local backend. This backend doesn't support this
|
|
|
|
operation.
|
|
|
|
`
|
|
|
|
|
2021-02-02 09:35:45 -06:00
|
|
|
// ModulePath returns the path to the root module and validates CLI arguments.
|
2017-01-18 22:50:45 -06:00
|
|
|
//
|
2021-02-02 09:35:45 -06:00
|
|
|
// This centralizes the logic for any commands that previously accepted
|
|
|
|
// a module path via CLI arguments. This will error if any extraneous arguments
|
|
|
|
// are given and suggest using the -chdir flag instead.
|
2017-01-18 22:50:45 -06:00
|
|
|
//
|
|
|
|
// If your command accepts more than one arg, then change the slice bounds
|
|
|
|
// to pass validation.
|
|
|
|
func ModulePath(args []string) (string, error) {
|
|
|
|
// TODO: test
|
|
|
|
|
2021-02-02 09:35:45 -06:00
|
|
|
if len(args) > 0 {
|
|
|
|
return "", fmt.Errorf("Too many command line arguments. Did you mean to use -chdir?")
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
|
|
|
|
2021-02-02 09:35:45 -06:00
|
|
|
path, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Error getting pwd: %s", err)
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
|
|
|
|
2021-02-02 09:35:45 -06:00
|
|
|
return path, nil
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|