2014-09-26 18:03:39 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-06-09 11:42:45 -05:00
|
|
|
"log"
|
2014-09-26 18:03:39 -05:00
|
|
|
"os"
|
2017-06-01 19:57:43 -05:00
|
|
|
"sort"
|
2014-09-26 18:03:39 -05:00
|
|
|
"strings"
|
|
|
|
|
2017-06-09 11:42:45 -05:00
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
2018-03-27 17:31:05 -05:00
|
|
|
"github.com/hashicorp/hcl2/hcl"
|
2017-05-03 10:02:47 -05:00
|
|
|
"github.com/hashicorp/terraform/backend"
|
2018-03-27 17:31:05 -05:00
|
|
|
backendinit "github.com/hashicorp/terraform/backend/init"
|
2014-09-26 18:03:39 -05:00
|
|
|
"github.com/hashicorp/terraform/config"
|
2018-03-27 17:31:05 -05:00
|
|
|
"github.com/hashicorp/terraform/config/configschema"
|
|
|
|
"github.com/hashicorp/terraform/configs"
|
2017-06-01 13:36:30 -05:00
|
|
|
"github.com/hashicorp/terraform/plugin"
|
2017-05-03 10:02:47 -05:00
|
|
|
"github.com/hashicorp/terraform/plugin/discovery"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2018-03-27 17:31:05 -05:00
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2014-09-26 18:03:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// InitCommand is a Command implementation that takes a Terraform
|
|
|
|
// module and clones it to the working directory.
|
|
|
|
type InitCommand struct {
|
|
|
|
Meta
|
2017-05-04 12:01:05 -05:00
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
// getPlugins is for the -get-plugins flag
|
|
|
|
getPlugins bool
|
|
|
|
|
2017-06-12 20:22:47 -05:00
|
|
|
// providerInstaller is used to download and install providers that
|
|
|
|
// aren't found locally. This uses a discovery.ProviderInstaller instance
|
|
|
|
// by default, but it can be overridden here as a way to mock fetching
|
|
|
|
// providers for tests.
|
|
|
|
providerInstaller discovery.Installer
|
2014-09-26 18:03:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) Run(args []string) int {
|
2017-07-28 17:23:29 -05:00
|
|
|
var flagFromModule string
|
2017-06-15 14:23:16 -05:00
|
|
|
var flagBackend, flagGet, flagUpgrade bool
|
2017-06-15 13:26:12 -05:00
|
|
|
var flagPluginPath FlagStringSlice
|
2017-06-20 10:46:33 -05:00
|
|
|
var flagVerifyPlugins bool
|
2018-03-27 17:31:05 -05:00
|
|
|
flagConfigExtra := newRawFlags("-backend-config")
|
2017-03-21 14:05:51 -05:00
|
|
|
|
2017-03-07 22:09:48 -06:00
|
|
|
args, err := c.Meta.process(args, false)
|
|
|
|
if err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
cmdFlags := c.flagSet("init")
|
|
|
|
cmdFlags.BoolVar(&flagBackend, "backend", true, "")
|
2018-03-27 17:31:05 -05:00
|
|
|
cmdFlags.Var(flagConfigExtra, "backend-config", "")
|
2017-07-28 17:23:29 -05:00
|
|
|
cmdFlags.StringVar(&flagFromModule, "from-module", "", "copy the source of the given module into the directory before init")
|
2017-01-18 22:50:45 -06:00
|
|
|
cmdFlags.BoolVar(&flagGet, "get", true, "")
|
2017-06-15 14:23:16 -05:00
|
|
|
cmdFlags.BoolVar(&c.getPlugins, "get-plugins", true, "")
|
2017-03-21 14:05:51 -05:00
|
|
|
cmdFlags.BoolVar(&c.forceInitCopy, "force-copy", false, "suppress prompts about copying state data")
|
2017-04-01 15:19:59 -05:00
|
|
|
cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state")
|
|
|
|
cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout")
|
2017-04-20 16:26:50 -05:00
|
|
|
cmdFlags.BoolVar(&c.reconfigure, "reconfigure", false, "reconfigure")
|
2017-06-12 16:14:40 -05:00
|
|
|
cmdFlags.BoolVar(&flagUpgrade, "upgrade", false, "")
|
2017-06-15 13:26:12 -05:00
|
|
|
cmdFlags.Var(&flagPluginPath, "plugin-dir", "plugin directory")
|
2017-06-20 10:46:33 -05:00
|
|
|
cmdFlags.BoolVar(&flagVerifyPlugins, "verify-plugins", true, "verify plugins")
|
2017-03-21 14:05:51 -05:00
|
|
|
|
2014-09-26 18:03:39 -05:00
|
|
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
|
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:31:05 -05:00
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
if len(flagPluginPath) > 0 {
|
|
|
|
c.pluginPath = flagPluginPath
|
|
|
|
c.getPlugins = false
|
|
|
|
}
|
2017-06-15 13:26:12 -05:00
|
|
|
|
2017-09-01 18:05:05 -05:00
|
|
|
// set providerInstaller if we don't have a test version already
|
2017-06-12 20:22:47 -05:00
|
|
|
if c.providerInstaller == nil {
|
|
|
|
c.providerInstaller = &discovery.ProviderInstaller{
|
2018-09-09 12:18:08 -05:00
|
|
|
Dir: c.pluginDir(),
|
|
|
|
Cache: c.pluginCache(),
|
2017-06-12 20:22:47 -05:00
|
|
|
PluginProtocolVersion: plugin.Handshake.ProtocolVersion,
|
2017-06-20 10:46:33 -05:00
|
|
|
SkipVerify: !flagVerifyPlugins,
|
2017-08-14 06:32:48 -05:00
|
|
|
Ui: c.Ui,
|
2017-06-12 20:22:47 -05:00
|
|
|
}
|
2017-05-04 12:01:05 -05:00
|
|
|
}
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// Validate the arg count
|
2014-09-26 18:03:39 -05:00
|
|
|
args = cmdFlags.Args()
|
2017-06-02 15:13:11 -05:00
|
|
|
if len(args) > 1 {
|
|
|
|
c.Ui.Error("The init command expects at most one argument.\n")
|
2014-09-26 18:03:39 -05:00
|
|
|
cmdFlags.Usage()
|
|
|
|
return 1
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
|
|
|
|
2017-06-15 13:26:12 -05:00
|
|
|
if err := c.storePluginPath(c.pluginPath); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error saving -plugin-path values: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// Get our pwd. We don't always need it but always getting it is easier
|
|
|
|
// than the logic to determine if it is or isn't needed.
|
|
|
|
pwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error getting pwd: %s", err))
|
2014-09-26 18:03:39 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:23:29 -05:00
|
|
|
// If an argument is provided then it overrides our working directory.
|
2017-06-02 15:13:11 -05:00
|
|
|
path := pwd
|
|
|
|
if len(args) == 1 {
|
|
|
|
path = args[0]
|
2014-09-26 18:03:39 -05:00
|
|
|
}
|
2016-01-19 19:13:19 -06:00
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// This will track whether we outputted anything so that we know whether
|
|
|
|
// to output a newline before the success message
|
|
|
|
var header bool
|
|
|
|
|
2017-07-28 17:23:29 -05:00
|
|
|
if flagFromModule != "" {
|
|
|
|
src := flagFromModule
|
|
|
|
|
|
|
|
empty, err := config.IsEmptyDir(path)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error validating destination directory: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if !empty {
|
|
|
|
c.Ui.Error(strings.TrimSpace(errInitCopyNotEmpty))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
|
|
|
|
"[reset][bold]Copying configuration[reset] from %q...", src,
|
|
|
|
)))
|
|
|
|
header = true
|
|
|
|
|
2018-03-27 17:31:05 -05:00
|
|
|
hooks := uiModuleInstallHooks{
|
|
|
|
Ui: c.Ui,
|
|
|
|
ShowLocalPaths: false, // since they are in a weird location for init
|
|
|
|
}
|
|
|
|
|
|
|
|
initDiags := c.initDirFromModule(path, src, hooks)
|
|
|
|
diags = diags.Append(initDiags)
|
|
|
|
if initDiags.HasErrors() {
|
|
|
|
c.showDiagnostics(diags)
|
2017-07-28 17:23:29 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// If our directory is empty, then we're done. We can't get or setup
|
|
|
|
// the backend with an empty directory.
|
2018-03-27 17:31:05 -05:00
|
|
|
if empty, err := config.IsEmptyDir(path); err != nil {
|
|
|
|
diags = diags.Append(fmt.Errorf("Error checking configuration: %s", err))
|
2014-09-26 18:03:39 -05:00
|
|
|
return 1
|
2018-07-04 05:11:35 -05:00
|
|
|
}
|
|
|
|
if empty {
|
2017-01-18 22:50:45 -06:00
|
|
|
c.Ui.Output(c.Colorize().Color(strings.TrimSpace(outputInitEmpty)))
|
|
|
|
return 0
|
2014-09-26 18:03:39 -05:00
|
|
|
}
|
|
|
|
|
2017-05-03 10:02:47 -05:00
|
|
|
var back backend.Backend
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// If we're performing a get or loading the backend, then we perform
|
|
|
|
// some extra tasks.
|
|
|
|
if flagGet || flagBackend {
|
2018-03-27 17:31:05 -05:00
|
|
|
config, confDiags := c.loadSingleModule(path)
|
|
|
|
diags = diags.Append(confDiags)
|
|
|
|
if confDiags.HasErrors() {
|
2017-10-05 14:00:45 -05:00
|
|
|
// Since this may be the user's first ever interaction with Terraform,
|
|
|
|
// we'll provide some additional context in this case.
|
|
|
|
c.Ui.Error(strings.TrimSpace(errInitConfigError))
|
2018-03-27 17:31:05 -05:00
|
|
|
c.showDiagnostics(diags)
|
2014-10-09 19:16:17 -05:00
|
|
|
return 1
|
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
|
|
|
|
// If we requested downloading modules and have modules in the config
|
2018-03-27 17:31:05 -05:00
|
|
|
if flagGet && len(config.ModuleCalls) > 0 {
|
2017-01-18 22:50:45 -06:00
|
|
|
header = true
|
|
|
|
|
2017-06-12 16:14:40 -05:00
|
|
|
if flagUpgrade {
|
2018-03-27 17:31:05 -05:00
|
|
|
c.Ui.Output(c.Colorize().Color(fmt.Sprintf("[reset][bold]Upgrading modules...")))
|
2017-06-12 16:14:40 -05:00
|
|
|
} else {
|
2018-03-27 17:31:05 -05:00
|
|
|
c.Ui.Output(c.Colorize().Color(fmt.Sprintf("[reset][bold]Initializing modules...")))
|
2017-06-12 16:14:40 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 17:31:05 -05:00
|
|
|
hooks := uiModuleInstallHooks{
|
|
|
|
Ui: c.Ui,
|
|
|
|
ShowLocalPaths: true,
|
|
|
|
}
|
|
|
|
instDiags := c.installModules(path, flagUpgrade, hooks)
|
|
|
|
diags = diags.Append(instDiags)
|
|
|
|
if instDiags.HasErrors() {
|
|
|
|
c.showDiagnostics(diags)
|
2015-02-22 12:49:31 -06:00
|
|
|
return 1
|
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
|
|
|
|
2017-05-03 10:02:47 -05:00
|
|
|
// If we're requesting backend configuration or looking for required
|
|
|
|
// plugins, load the backend
|
2017-06-15 14:23:16 -05:00
|
|
|
if flagBackend {
|
2017-01-18 22:50:45 -06:00
|
|
|
header = true
|
|
|
|
|
2018-03-27 17:31:05 -05:00
|
|
|
var backendSchema *configschema.Block
|
|
|
|
|
2017-02-15 17:44:53 -06:00
|
|
|
// Only output that we're initializing a backend if we have
|
|
|
|
// something in the config. We can be UNSETTING a backend as well
|
|
|
|
// in which case we choose not to show this.
|
2018-03-27 17:31:05 -05:00
|
|
|
if config.Backend != nil {
|
|
|
|
c.Ui.Output(c.Colorize().Color(fmt.Sprintf("\n[reset][bold]Initializing the backend...")))
|
|
|
|
|
|
|
|
backendType := config.Backend.Type
|
|
|
|
bf := backendinit.Backend(backendType)
|
|
|
|
if bf == nil {
|
|
|
|
diags = diags.Append(&hcl.Diagnostic{
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
Summary: "Unsupported backend type",
|
|
|
|
Detail: fmt.Sprintf("There is no backend type named %q.", backendType),
|
|
|
|
Subject: &config.Backend.TypeRange,
|
|
|
|
})
|
|
|
|
c.showDiagnostics()
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
b := bf()
|
|
|
|
backendSchema = b.ConfigSchema()
|
|
|
|
}
|
|
|
|
|
|
|
|
var backendConfigOverride hcl.Body
|
|
|
|
if backendSchema != nil {
|
|
|
|
var overrideDiags tfdiags.Diagnostics
|
|
|
|
backendConfigOverride, overrideDiags = c.backendConfigOverrideBody(flagConfigExtra, backendSchema)
|
|
|
|
diags = diags.Append(overrideDiags)
|
|
|
|
if overrideDiags.HasErrors() {
|
|
|
|
c.showDiagnostics()
|
|
|
|
return 1
|
|
|
|
}
|
2017-02-15 17:44:53 -06:00
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
|
|
|
|
opts := &BackendOpts{
|
2018-03-27 17:31:05 -05:00
|
|
|
Config: config.Backend,
|
|
|
|
ConfigOverride: backendConfigOverride,
|
|
|
|
Init: true,
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
2018-03-27 17:31:05 -05:00
|
|
|
var backDiags tfdiags.Diagnostics
|
|
|
|
back, backDiags = c.Backend(opts)
|
|
|
|
diags = diags.Append(backDiags)
|
|
|
|
if backDiags.HasErrors() {
|
|
|
|
c.showDiagnostics(diags)
|
2015-02-22 12:49:31 -06:00
|
|
|
return 1
|
|
|
|
}
|
2014-09-30 18:05:40 -05:00
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
}
|
2014-10-09 19:16:17 -05:00
|
|
|
|
2017-06-21 12:32:13 -05:00
|
|
|
if back == nil {
|
|
|
|
// If we didn't initialize a backend then we'll try to at least
|
|
|
|
// instantiate one. This might fail if it wasn't already initalized
|
|
|
|
// by a previous run, so we must still expect that "back" may be nil
|
|
|
|
// in code that follows.
|
2018-03-27 17:31:05 -05:00
|
|
|
var backDiags tfdiags.Diagnostics
|
|
|
|
back, backDiags = c.Backend(nil)
|
|
|
|
if backDiags.HasErrors() {
|
2017-06-21 12:32:13 -05:00
|
|
|
// This is fine. We'll proceed with no backend, then.
|
|
|
|
back = nil
|
|
|
|
}
|
2017-06-15 14:23:16 -05:00
|
|
|
}
|
2017-05-03 10:02:47 -05:00
|
|
|
|
2017-06-21 12:32:13 -05:00
|
|
|
var state *terraform.State
|
|
|
|
|
|
|
|
// If we have a functional backend (either just initialized or initialized
|
|
|
|
// on a previous run) we'll use the current state as a potential source
|
|
|
|
// of provider dependencies.
|
|
|
|
if back != nil {
|
|
|
|
sMgr, err := back.State(c.Workspace())
|
|
|
|
if err != nil {
|
2018-07-04 10:24:49 -05:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error loading state: %s", err))
|
2017-06-21 12:32:13 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := sMgr.RefreshState(); err != nil {
|
2018-07-04 10:24:49 -05:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error refreshing state: %s", err))
|
2017-06-21 12:32:13 -05:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
state = sMgr.State()
|
2017-06-15 14:23:16 -05:00
|
|
|
}
|
2017-05-03 10:02:47 -05:00
|
|
|
|
2017-07-03 12:59:13 -05:00
|
|
|
if v := os.Getenv(ProviderSkipVerifyEnvVar); v != "" {
|
|
|
|
c.ignorePluginChecksum = true
|
|
|
|
}
|
|
|
|
|
2017-06-21 12:32:13 -05:00
|
|
|
// Now that we have loaded all modules, check the module tree for missing providers.
|
|
|
|
err = c.getProviders(path, state, flagUpgrade)
|
2017-06-15 14:23:16 -05:00
|
|
|
if err != nil {
|
|
|
|
// this function provides its own output
|
|
|
|
log.Printf("[ERROR] %s", err)
|
|
|
|
return 1
|
2017-05-03 10:02:47 -05:00
|
|
|
}
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
// If we outputted information, then we need to output a newline
|
|
|
|
// so that our success message is nicely spaced out from prior text.
|
|
|
|
if header {
|
|
|
|
c.Ui.Output("")
|
2014-09-30 18:05:40 -05:00
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
|
|
|
|
c.Ui.Output(c.Colorize().Color(strings.TrimSpace(outputInitSuccess)))
|
2017-09-08 19:14:37 -05:00
|
|
|
if !c.RunningInAutomation {
|
|
|
|
// If we're not running in an automation wrapper, give the user
|
|
|
|
// some more detailed next steps that are appropriate for interactive
|
|
|
|
// shell usage.
|
|
|
|
c.Ui.Output(c.Colorize().Color(strings.TrimSpace(outputInitSuccessCLI)))
|
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
|
2014-09-26 18:03:39 -05:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:31:05 -05:00
|
|
|
// backendConfigOverrideBody interprets the raw values of -backend-config
|
|
|
|
// arguments into a hcl Body that should override the backend settings given
|
|
|
|
// in the configuration.
|
|
|
|
//
|
|
|
|
// If the result is nil then no override needs to be provided.
|
|
|
|
//
|
|
|
|
// If the returned diagnostics contains errors then the returned body may be
|
|
|
|
// incomplete or invalid.
|
|
|
|
func (c *InitCommand) backendConfigOverrideBody(flags rawFlags, schema *configschema.Block) (hcl.Body, tfdiags.Diagnostics) {
|
|
|
|
items := flags.AllItems()
|
|
|
|
if len(items) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var ret hcl.Body
|
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
synthVals := make(map[string]cty.Value)
|
|
|
|
|
|
|
|
mergeBody := func(newBody hcl.Body) {
|
|
|
|
if ret == nil {
|
|
|
|
ret = newBody
|
|
|
|
} else {
|
|
|
|
ret = configs.MergeBodies(ret, newBody)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flushVals := func() {
|
|
|
|
if len(synthVals) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newBody := configs.SynthBody("-backend-config=...", synthVals)
|
|
|
|
mergeBody(newBody)
|
|
|
|
synthVals = make(map[string]cty.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range items {
|
|
|
|
eq := strings.Index(item.Value, "=")
|
|
|
|
|
|
|
|
if eq == -1 {
|
|
|
|
// The value is interpreted as a filename.
|
|
|
|
newBody, fileDiags := c.loadHCLFile(item.Value)
|
|
|
|
diags = diags.Append(fileDiags)
|
|
|
|
flushVals() // deal with any accumulated individual values first
|
|
|
|
mergeBody(newBody)
|
|
|
|
} else {
|
|
|
|
name := item.Value[:eq]
|
|
|
|
rawValue := item.Value[eq+1:]
|
|
|
|
attrS := schema.Attributes[name]
|
|
|
|
if attrS == nil {
|
|
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
|
|
tfdiags.Error,
|
|
|
|
"Invalid backend configuration argument",
|
|
|
|
fmt.Sprintf("The backend configuration argument %q given on the command line is not expected for the selected backend type.", name),
|
|
|
|
))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
value, valueDiags := configValueFromCLI(item.String(), rawValue, attrS.Type)
|
|
|
|
diags = diags.Append(valueDiags)
|
|
|
|
if valueDiags.HasErrors() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
synthVals[name] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flushVals()
|
|
|
|
|
|
|
|
return ret, diags
|
|
|
|
}
|
|
|
|
|
2017-06-09 11:42:45 -05:00
|
|
|
// Load the complete module tree, and fetch any missing providers.
|
|
|
|
// This method outputs its own Ui.
|
2017-06-12 20:22:47 -05:00
|
|
|
func (c *InitCommand) getProviders(path string, state *terraform.State, upgrade bool) error {
|
command: validate config as part of loading it
Previously we required callers to separately call .Validate on the root
module to determine if there were any value errors, but we did that
inconsistently and would thus see crashes in some cases where later code
would try to use invalid configuration as if it were valid.
Now we run .Validate automatically after config loading, returning the
resulting diagnostics. Since we return a diagnostics here, it's possible
to return both warnings and errors.
We return the loaded module even if it's invalid, so callers are free to
ignore returned errors and try to work with the config anyway, though they
will need to be defensive against invalid configuration themselves in
that case.
As a result of this, all of the commands that load configuration now need
to use diagnostic printing to signal errors. For the moment this just
allows us to return potentially-multiple config errors/warnings in full
fidelity, but also sets us up for later when more subsystems are able
to produce rich diagnostics so we can show them all together.
Finally, this commit also removes some stale, commented-out code for the
"legacy" (pre-0.8) graph implementation, which has not been available
for some time.
2017-12-06 18:41:48 -06:00
|
|
|
mod, diags := c.Module(path)
|
|
|
|
if diags.HasErrors() {
|
|
|
|
c.showDiagnostics(diags)
|
|
|
|
return diags.Err()
|
2017-05-03 10:02:47 -05:00
|
|
|
}
|
|
|
|
|
2017-12-14 14:46:43 -06:00
|
|
|
if err := terraform.CheckStateVersion(state); err != nil {
|
|
|
|
diags = diags.Append(err)
|
|
|
|
c.showDiagnostics(diags)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-08-28 13:25:16 -05:00
|
|
|
if err := terraform.CheckRequiredVersion(mod); err != nil {
|
command: validate config as part of loading it
Previously we required callers to separately call .Validate on the root
module to determine if there were any value errors, but we did that
inconsistently and would thus see crashes in some cases where later code
would try to use invalid configuration as if it were valid.
Now we run .Validate automatically after config loading, returning the
resulting diagnostics. Since we return a diagnostics here, it's possible
to return both warnings and errors.
We return the loaded module even if it's invalid, so callers are free to
ignore returned errors and try to work with the config anyway, though they
will need to be defensive against invalid configuration themselves in
that case.
As a result of this, all of the commands that load configuration now need
to use diagnostic printing to signal errors. For the moment this just
allows us to return potentially-multiple config errors/warnings in full
fidelity, but also sets us up for later when more subsystems are able
to produce rich diagnostics so we can show them all together.
Finally, this commit also removes some stale, commented-out code for the
"legacy" (pre-0.8) graph implementation, which has not been available
for some time.
2017-12-06 18:41:48 -06:00
|
|
|
diags = diags.Append(err)
|
|
|
|
c.showDiagnostics(diags)
|
2017-08-28 13:25:16 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:32:42 -05:00
|
|
|
var available discovery.PluginMetaSet
|
|
|
|
if upgrade {
|
|
|
|
// If we're in upgrade mode, we ignore any auto-installed plugins
|
|
|
|
// in "available", causing us to reinstall and possibly upgrade them.
|
|
|
|
available = c.providerPluginManuallyInstalledSet()
|
|
|
|
} else {
|
|
|
|
available = c.providerPluginSet()
|
|
|
|
}
|
2017-06-19 09:23:58 -05:00
|
|
|
|
2017-05-03 10:02:47 -05:00
|
|
|
requirements := terraform.ModuleTreeDependencies(mod, state).AllPluginRequirements()
|
2017-06-19 09:23:58 -05:00
|
|
|
if len(requirements) == 0 {
|
|
|
|
// nothing to initialize
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(c.Colorize().Color(
|
|
|
|
"\n[reset][bold]Initializing provider plugins...",
|
|
|
|
))
|
|
|
|
|
2017-05-24 19:35:46 -05:00
|
|
|
missing := c.missingPlugins(available, requirements)
|
2017-05-03 10:02:47 -05:00
|
|
|
|
2017-06-09 11:42:45 -05:00
|
|
|
var errs error
|
2017-06-15 14:23:16 -05:00
|
|
|
if c.getPlugins {
|
2017-08-14 06:32:48 -05:00
|
|
|
if len(missing) > 0 {
|
2017-08-17 02:43:09 -05:00
|
|
|
c.Ui.Output(fmt.Sprintf("- Checking for available provider plugins on %s...",
|
2017-08-14 06:32:48 -05:00
|
|
|
discovery.GetReleaseHost()))
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
for provider, reqd := range missing {
|
|
|
|
_, err := c.providerInstaller.Get(provider, reqd.Versions)
|
|
|
|
|
|
|
|
if err != nil {
|
2017-06-19 20:49:37 -05:00
|
|
|
switch err {
|
|
|
|
case discovery.ErrorNoSuchProvider:
|
|
|
|
c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
|
|
|
|
case discovery.ErrorNoSuitableVersion:
|
2017-06-20 19:40:28 -05:00
|
|
|
if reqd.Versions.Unconstrained() {
|
|
|
|
// This should never happen, but might crop up if we catch
|
|
|
|
// the releases server in a weird state where the provider's
|
|
|
|
// directory is present but does not yet contain any
|
|
|
|
// versions. We'll treat it like ErrorNoSuchProvider, then.
|
|
|
|
c.Ui.Error(fmt.Sprintf(errProviderNotFound, provider, DefaultPluginVendorDir))
|
|
|
|
} else {
|
|
|
|
c.Ui.Error(fmt.Sprintf(errProviderVersionsUnsuitable, provider, reqd.Versions))
|
|
|
|
}
|
2017-06-19 20:49:37 -05:00
|
|
|
case discovery.ErrorNoVersionCompatible:
|
|
|
|
// FIXME: This error message is sub-awesome because we don't
|
|
|
|
// have enough information here to tell the user which versions
|
|
|
|
// we considered and which versions might be compatible.
|
2017-06-20 19:40:28 -05:00
|
|
|
constraint := reqd.Versions.String()
|
|
|
|
if constraint == "" {
|
|
|
|
constraint = "(any version)"
|
|
|
|
}
|
|
|
|
c.Ui.Error(fmt.Sprintf(errProviderIncompatible, provider, constraint))
|
2017-06-19 20:49:37 -05:00
|
|
|
default:
|
|
|
|
c.Ui.Error(fmt.Sprintf(errProviderInstallError, provider, err.Error(), DefaultPluginVendorDir))
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
errs = multierror.Append(errs, err)
|
|
|
|
}
|
|
|
|
}
|
2017-06-09 11:42:45 -05:00
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
if errs != nil {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
} else if len(missing) > 0 {
|
|
|
|
// we have missing providers, but aren't going to try and download them
|
2017-06-19 20:49:37 -05:00
|
|
|
var lines []string
|
2017-06-15 14:23:16 -05:00
|
|
|
for provider, reqd := range missing {
|
2017-06-19 20:49:37 -05:00
|
|
|
if reqd.Versions.Unconstrained() {
|
|
|
|
lines = append(lines, fmt.Sprintf("* %s (any version)\n", provider))
|
|
|
|
} else {
|
|
|
|
lines = append(lines, fmt.Sprintf("* %s (%s)\n", provider, reqd.Versions))
|
|
|
|
}
|
2017-06-15 14:23:16 -05:00
|
|
|
errs = multierror.Append(errs, fmt.Errorf("missing provider %q", provider))
|
2017-05-03 10:02:47 -05:00
|
|
|
}
|
2017-06-19 20:49:37 -05:00
|
|
|
sort.Strings(lines)
|
|
|
|
c.Ui.Error(fmt.Sprintf(errMissingProvidersNoInstall, strings.Join(lines, ""), DefaultPluginVendorDir))
|
2017-06-09 11:42:45 -05:00
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
2017-05-24 19:35:46 -05:00
|
|
|
// With all the providers downloaded, we'll generate our lock file
|
|
|
|
// that ensures the provider binaries remain unchanged until we init
|
|
|
|
// again. If anything changes, other commands that use providers will
|
|
|
|
// fail with an error instructing the user to re-run this command.
|
|
|
|
available = c.providerPluginSet() // re-discover to see newly-installed plugins
|
2018-01-05 10:52:11 -06:00
|
|
|
|
|
|
|
// internal providers were already filtered out, since we don't need to get them.
|
|
|
|
chosen := choosePlugins(available, nil, requirements)
|
|
|
|
|
2017-05-24 19:35:46 -05:00
|
|
|
digests := map[string][]byte{}
|
|
|
|
for name, meta := range chosen {
|
|
|
|
digest, err := meta.SHA256()
|
|
|
|
if err != nil {
|
2017-06-09 11:42:45 -05:00
|
|
|
c.Ui.Error(fmt.Sprintf("failed to read provider plugin %s: %s", meta.Path, err))
|
|
|
|
return err
|
2017-05-24 19:35:46 -05:00
|
|
|
}
|
|
|
|
digests[name] = digest
|
2017-07-03 12:59:13 -05:00
|
|
|
if c.ignorePluginChecksum {
|
|
|
|
digests[name] = nil
|
|
|
|
}
|
2017-05-24 19:35:46 -05:00
|
|
|
}
|
command: validate config as part of loading it
Previously we required callers to separately call .Validate on the root
module to determine if there were any value errors, but we did that
inconsistently and would thus see crashes in some cases where later code
would try to use invalid configuration as if it were valid.
Now we run .Validate automatically after config loading, returning the
resulting diagnostics. Since we return a diagnostics here, it's possible
to return both warnings and errors.
We return the loaded module even if it's invalid, so callers are free to
ignore returned errors and try to work with the config anyway, though they
will need to be defensive against invalid configuration themselves in
that case.
As a result of this, all of the commands that load configuration now need
to use diagnostic printing to signal errors. For the moment this just
allows us to return potentially-multiple config errors/warnings in full
fidelity, but also sets us up for later when more subsystems are able
to produce rich diagnostics so we can show them all together.
Finally, this commit also removes some stale, commented-out code for the
"legacy" (pre-0.8) graph implementation, which has not been available
for some time.
2017-12-06 18:41:48 -06:00
|
|
|
err := c.providerPluginsLock().Write(digests)
|
2017-05-24 19:35:46 -05:00
|
|
|
if err != nil {
|
2017-06-09 11:42:45 -05:00
|
|
|
c.Ui.Error(fmt.Sprintf("failed to save provider manifest: %s", err))
|
|
|
|
return err
|
2017-05-24 19:35:46 -05:00
|
|
|
}
|
|
|
|
|
2017-06-20 13:25:41 -05:00
|
|
|
{
|
2017-06-12 20:32:42 -05:00
|
|
|
// Purge any auto-installed plugins that aren't being used.
|
|
|
|
purged, err := c.providerInstaller.PurgeUnused(chosen)
|
|
|
|
if err != nil {
|
|
|
|
// Failure to purge old plugins is not a fatal error
|
|
|
|
c.Ui.Warn(fmt.Sprintf("failed to purge unused plugins: %s", err))
|
|
|
|
}
|
|
|
|
if purged != nil {
|
|
|
|
for meta := range purged {
|
|
|
|
log.Printf("[DEBUG] Purged unused %s plugin %s", meta.Name, meta.Path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-01 19:57:43 -05:00
|
|
|
// If any providers have "floating" versions (completely unconstrained)
|
|
|
|
// we'll suggest the user constrain with a pessimistic constraint to
|
|
|
|
// avoid implicitly adopting a later major release.
|
|
|
|
constraintSuggestions := make(map[string]discovery.ConstraintStr)
|
|
|
|
for name, meta := range chosen {
|
|
|
|
req := requirements[name]
|
|
|
|
if req == nil {
|
|
|
|
// should never happen, but we don't want to crash here, so we'll
|
|
|
|
// be cautious.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-06-16 15:19:13 -05:00
|
|
|
if req.Versions.Unconstrained() && meta.Version != discovery.VersionZero {
|
2017-06-01 19:57:43 -05:00
|
|
|
// meta.Version.MustParse is safe here because our "chosen" metas
|
|
|
|
// were already filtered for validity of versions.
|
|
|
|
constraintSuggestions[name] = meta.Version.MustParse().MinorUpgradeConstraintStr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(constraintSuggestions) != 0 {
|
|
|
|
names := make([]string, 0, len(constraintSuggestions))
|
|
|
|
for name := range constraintSuggestions {
|
|
|
|
names = append(names, name)
|
|
|
|
}
|
|
|
|
sort.Strings(names)
|
|
|
|
|
|
|
|
c.Ui.Output(outputInitProvidersUnconstrained)
|
|
|
|
for _, name := range names {
|
|
|
|
c.Ui.Output(fmt.Sprintf("* provider.%s: version = %q", name, constraintSuggestions[name]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-03 10:02:47 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-25 20:09:43 -05:00
|
|
|
func (c *InitCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictDirs("")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return complete.Flags{
|
|
|
|
"-backend": completePredictBoolean,
|
|
|
|
"-backend-config": complete.PredictFiles("*.tfvars"), // can also be key=value, but we can't "predict" that
|
|
|
|
"-force-copy": complete.PredictNothing,
|
|
|
|
"-from-module": completePredictModuleSource,
|
|
|
|
"-get": completePredictBoolean,
|
|
|
|
"-get-plugins": completePredictBoolean,
|
|
|
|
"-input": completePredictBoolean,
|
|
|
|
"-lock": completePredictBoolean,
|
|
|
|
"-lock-timeout": complete.PredictAnything,
|
|
|
|
"-no-color": complete.PredictNothing,
|
|
|
|
"-plugin-dir": complete.PredictDirs(""),
|
|
|
|
"-reconfigure": complete.PredictNothing,
|
|
|
|
"-upgrade": completePredictBoolean,
|
|
|
|
"-verify-plugins": completePredictBoolean,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 18:03:39 -05:00
|
|
|
func (c *InitCommand) Help() string {
|
|
|
|
helpText := `
|
2017-06-02 15:13:11 -05:00
|
|
|
Usage: terraform init [options] [DIR]
|
2017-01-18 22:50:45 -06:00
|
|
|
|
2017-06-02 18:59:52 -05:00
|
|
|
Initialize a new or existing Terraform working directory by creating
|
2017-01-18 22:50:45 -06:00
|
|
|
initial files, loading any remote state, downloading modules, etc.
|
|
|
|
|
|
|
|
This is the first command that should be run for any new or existing
|
|
|
|
Terraform configuration per machine. This sets up all the local data
|
2017-04-26 09:10:04 -05:00
|
|
|
necessary to run Terraform that is typically not committed to version
|
2017-01-18 22:50:45 -06:00
|
|
|
control.
|
|
|
|
|
|
|
|
This command is always safe to run multiple times. Though subsequent runs
|
2017-06-02 18:59:52 -05:00
|
|
|
may give errors, this command will never delete your configuration or
|
|
|
|
state. Even so, if you have important information, please back it up prior
|
|
|
|
to running this command, just in case.
|
2014-09-26 18:03:39 -05:00
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
If no arguments are given, the configuration in this working directory
|
|
|
|
is initialized.
|
2014-09-26 18:03:39 -05:00
|
|
|
|
2014-09-30 18:05:40 -05:00
|
|
|
Options:
|
|
|
|
|
2017-06-02 18:59:52 -05:00
|
|
|
-backend=true Configure the backend for this configuration.
|
2014-12-04 21:06:47 -06:00
|
|
|
|
2017-03-17 01:27:05 -05:00
|
|
|
-backend-config=path This can be either a path to an HCL file with key/value
|
|
|
|
assignments (same format as terraform.tfvars) or a
|
|
|
|
'key=value' format. This is merged with what is in the
|
|
|
|
configuration file. This can be specified multiple
|
|
|
|
times. The backend type must be in the configuration
|
|
|
|
itself.
|
2014-09-30 18:05:40 -05:00
|
|
|
|
2017-04-20 16:26:50 -05:00
|
|
|
-force-copy Suppress prompts about copying state data. This is
|
|
|
|
equivalent to providing a "yes" to all confirmation
|
|
|
|
prompts.
|
|
|
|
|
2017-07-28 17:23:29 -05:00
|
|
|
-from-module=SOURCE Copy the contents of the given module into the target
|
|
|
|
directory before initialization.
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
-get=true Download any modules for this configuration.
|
|
|
|
|
2017-05-03 10:02:47 -05:00
|
|
|
-get-plugins=true Download any missing plugins for this configuration.
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
-input=true Ask for input if necessary. If false, will error if
|
|
|
|
input was required.
|
|
|
|
|
2017-04-01 15:19:59 -05:00
|
|
|
-lock=true Lock the state file when locking is supported.
|
|
|
|
|
|
|
|
-lock-timeout=0s Duration to retry a state lock.
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
-no-color If specified, output won't contain any color.
|
2015-06-22 07:14:01 -05:00
|
|
|
|
2017-06-15 14:23:16 -05:00
|
|
|
-plugin-dir Directory containing plugin binaries. This overrides all
|
|
|
|
default search paths for plugins, and prevents the
|
|
|
|
automatic installation of plugins. This flag can be used
|
|
|
|
multiple times.
|
|
|
|
|
2017-06-20 10:46:33 -05:00
|
|
|
-reconfigure Reconfigure the backend, ignoring any saved
|
|
|
|
configuration.
|
2017-06-12 16:14:40 -05:00
|
|
|
|
|
|
|
-upgrade=false If installing modules (-get) or plugins (-get-plugins),
|
|
|
|
ignore previously-downloaded objects and install the
|
|
|
|
latest version allowed within configured constraints.
|
2017-06-20 10:46:33 -05:00
|
|
|
|
|
|
|
-verify-plugins=true Verify the authenticity and integrity of automatically
|
|
|
|
downloaded plugins.
|
2014-09-26 18:03:39 -05:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) Synopsis() string {
|
2017-07-28 17:23:29 -05:00
|
|
|
return "Initialize a Terraform working directory"
|
2014-09-26 18:03:39 -05:00
|
|
|
}
|
2017-01-18 22:50:45 -06:00
|
|
|
|
2017-10-05 14:00:45 -05:00
|
|
|
const errInitConfigError = `
|
|
|
|
There are some problems with the configuration, described below.
|
|
|
|
|
|
|
|
The Terraform configuration must be valid before initialization so that
|
|
|
|
Terraform can determine which modules and providers need to be installed.
|
|
|
|
`
|
|
|
|
|
2017-01-18 22:50:45 -06:00
|
|
|
const errInitCopyNotEmpty = `
|
2017-07-28 17:23:29 -05:00
|
|
|
The working directory already contains files. The -from-module option requires
|
|
|
|
an empty directory into which a copy of the referenced module will be placed.
|
2017-01-18 22:50:45 -06:00
|
|
|
|
2017-07-28 17:23:29 -05:00
|
|
|
To initialize the configuration already in this working directory, omit the
|
|
|
|
-from-module option.
|
2017-01-18 22:50:45 -06:00
|
|
|
`
|
|
|
|
|
|
|
|
const outputInitEmpty = `
|
|
|
|
[reset][bold]Terraform initialized in an empty directory![reset]
|
|
|
|
|
|
|
|
The directory has no Terraform configuration files. You may begin working
|
|
|
|
with Terraform immediately by creating Terraform configuration files.
|
|
|
|
`
|
|
|
|
|
|
|
|
const outputInitSuccess = `
|
|
|
|
[reset][bold][green]Terraform has been successfully initialized![reset][green]
|
2017-09-08 19:14:37 -05:00
|
|
|
`
|
2017-01-18 22:50:45 -06:00
|
|
|
|
2017-09-08 19:14:37 -05:00
|
|
|
const outputInitSuccessCLI = `[reset][green]
|
2017-01-18 22:50:45 -06:00
|
|
|
You may now begin working with Terraform. Try running "terraform plan" to see
|
|
|
|
any changes that are required for your infrastructure. All Terraform commands
|
|
|
|
should now work.
|
|
|
|
|
|
|
|
If you ever set or change modules or backend configuration for Terraform,
|
2017-06-02 18:59:52 -05:00
|
|
|
rerun this command to reinitialize your working directory. If you forget, other
|
2017-01-18 22:50:45 -06:00
|
|
|
commands will detect it and remind you to do so if necessary.
|
|
|
|
`
|
2017-06-01 19:57:43 -05:00
|
|
|
|
|
|
|
const outputInitProvidersUnconstrained = `
|
|
|
|
The following providers do not have any version constraints in configuration,
|
|
|
|
so the latest version was installed.
|
|
|
|
|
|
|
|
To prevent automatic upgrades to new major versions that may contain breaking
|
|
|
|
changes, it is recommended to add version = "..." constraints to the
|
|
|
|
corresponding provider blocks in configuration, with the constraint strings
|
|
|
|
suggested below.
|
|
|
|
`
|
2017-06-09 11:42:45 -05:00
|
|
|
|
|
|
|
const errProviderNotFound = `
|
2017-06-19 20:49:37 -05:00
|
|
|
[reset][bold][red]Provider %[1]q not available for installation.[reset][red]
|
|
|
|
|
|
|
|
A provider named %[1]q could not be found in the official repository.
|
|
|
|
|
|
|
|
This may result from mistyping the provider name, or the given provider may
|
|
|
|
be a third-party provider that cannot be installed automatically.
|
|
|
|
|
|
|
|
In the latter case, the plugin must be installed manually by locating and
|
|
|
|
downloading a suitable distribution package and placing the plugin's executable
|
|
|
|
file in the following directory:
|
|
|
|
%[2]s
|
|
|
|
|
|
|
|
Terraform detects necessary plugins by inspecting the configuration and state.
|
|
|
|
To view the provider versions requested by each module, run
|
|
|
|
"terraform providers".
|
|
|
|
`
|
|
|
|
|
|
|
|
const errProviderVersionsUnsuitable = `
|
|
|
|
[reset][bold][red]No provider %[1]q plugins meet the constraint %[2]q.[reset][red]
|
|
|
|
|
|
|
|
The version constraint is derived from the "version" argument within the
|
|
|
|
provider %[1]q block in configuration. Child modules may also apply
|
|
|
|
provider version constraints. To view the provider versions requested by each
|
|
|
|
module in the current configuration, run "terraform providers".
|
|
|
|
|
|
|
|
To proceed, the version constraints for this provider must be relaxed by
|
|
|
|
either adjusting or removing the "version" argument in the provider blocks
|
|
|
|
throughout the configuration.
|
|
|
|
`
|
|
|
|
|
|
|
|
const errProviderIncompatible = `
|
|
|
|
[reset][bold][red]No available provider %[1]q plugins are compatible with this Terraform version.[reset][red]
|
|
|
|
|
|
|
|
From time to time, new Terraform major releases can change the requirements for
|
|
|
|
plugins such that older plugins become incompatible.
|
|
|
|
|
|
|
|
Terraform checked all of the plugin versions matching the given constraint:
|
|
|
|
%[2]s
|
|
|
|
|
|
|
|
Unfortunately, none of the suitable versions are compatible with this version
|
|
|
|
of Terraform. If you have recently upgraded Terraform, it may be necessary to
|
|
|
|
move to a newer major release of this provider. Alternatively, if you are
|
|
|
|
attempting to upgrade the provider to a new major version you may need to
|
|
|
|
also upgrade Terraform to support the new version.
|
|
|
|
|
|
|
|
Consult the documentation for this provider for more information on
|
|
|
|
compatibility between provider versions and Terraform versions.
|
|
|
|
`
|
|
|
|
|
|
|
|
const errProviderInstallError = `
|
|
|
|
[reset][bold][red]Error installing provider %[1]q: %[2]s.[reset][red]
|
|
|
|
|
|
|
|
Terraform analyses the configuration and state and automatically downloads
|
|
|
|
plugins for the providers used. However, when attempting to download this
|
|
|
|
plugin an unexpected error occured.
|
|
|
|
|
|
|
|
This may be caused if for some reason Terraform is unable to reach the
|
|
|
|
plugin repository. The repository may be unreachable if access is blocked
|
|
|
|
by a firewall.
|
|
|
|
|
|
|
|
If automatic installation is not possible or desirable in your environment,
|
|
|
|
you may alternatively manually install plugins by downloading a suitable
|
|
|
|
distribution package and placing the plugin's executable file in the
|
|
|
|
following directory:
|
|
|
|
%[3]s
|
|
|
|
`
|
|
|
|
|
|
|
|
const errMissingProvidersNoInstall = `
|
|
|
|
[reset][bold][red]Missing required providers.[reset][red]
|
2017-06-09 11:42:45 -05:00
|
|
|
|
2017-06-19 20:49:37 -05:00
|
|
|
The following provider constraints are not met by the currently-installed
|
|
|
|
provider plugins:
|
2017-06-09 11:42:45 -05:00
|
|
|
|
2017-06-19 20:49:37 -05:00
|
|
|
%[1]s
|
|
|
|
Terraform can automatically download and install plugins to meet the given
|
|
|
|
constraints, but this step was skipped due to the use of -get-plugins=false
|
|
|
|
and/or -plugin-dir on the command line.
|
2017-06-09 11:42:45 -05:00
|
|
|
|
2017-06-19 20:49:37 -05:00
|
|
|
If automatic installation is not possible or desirable in your environment,
|
|
|
|
you may manually install plugins by downloading a suitable distribution package
|
|
|
|
and placing the plugin's executable file in one of the directories given in
|
|
|
|
by -plugin-dir on the command line, or in the following directory if custom
|
|
|
|
plugin directories are not set:
|
|
|
|
%[2]s
|
2017-06-09 11:42:45 -05:00
|
|
|
`
|