From 3f0c6a221708a670f5c3f6698610ac2dc99d91dd Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Wed, 2 Jun 2021 15:30:05 -0400 Subject: [PATCH] cli: Add -ignore-remote-version flag for init When performing state migration to a remote backend target, Terraform may fail due to mismatched remote and local Terraform versions. Here we add the `-ignore-remote-version` flag to allow users to ignore this version check when necessary. --- internal/command/init.go | 62 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/internal/command/init.go b/internal/command/init.go index 29f97215b..96a383159 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -49,6 +49,7 @@ func (c *InitCommand) Run(args []string) int { cmdFlags.BoolVar(&flagUpgrade, "upgrade", false, "") cmdFlags.Var(&flagPluginPath, "plugin-dir", "plugin directory") cmdFlags.StringVar(&flagLockfile, "lockfile", "", "Set a dependency lockfile mode") + cmdFlags.BoolVar(&c.Meta.ignoreRemoteVersion, "ignore-remote-version", false, "continue even if remote and local Terraform versions are incompatible") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -962,46 +963,49 @@ Usage: terraform [global options] init [options] Options: - -backend=true Configure the backend for this configuration. + -backend=true Configure the backend for this configuration. - -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. + -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. - -force-copy Suppress prompts about copying state data. This is - equivalent to providing a "yes" to all confirmation - prompts. + -force-copy Suppress prompts about copying state data. This is + equivalent to providing a "yes" to all confirmation + prompts. - -from-module=SOURCE Copy the contents of the given module into the target - directory before initialization. + -from-module=SOURCE Copy the contents of the given module into the target + directory before initialization. - -get=true Download any modules for this configuration. + -get=true Download any modules for this configuration. - -input=true Ask for input if necessary. If false, will error if - input was required. + -input=true Ask for input if necessary. If false, will error if + input was required. - -no-color If specified, output won't contain any color. + -no-color If specified, output won't contain any color. - -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. + -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. - -reconfigure Reconfigure the backend, ignoring any saved - configuration. + -reconfigure Reconfigure the backend, ignoring any saved + configuration. - -migrate-state Reconfigure the backend, and attempt to migrate any - existing state. + -migrate-state Reconfigure the backend, and attempt to migrate any + existing state. - -upgrade=false If installing modules (-get) or plugins, ignore - previously-downloaded objects and install the - latest version allowed within configured constraints. + -upgrade=false If installing modules (-get) or plugins, ignore + previously-downloaded objects and install the + latest version allowed within configured constraints. - -lockfile=MODE Set a dependency lockfile mode. - Currently only "readonly" is valid. + -lockfile=MODE Set a dependency lockfile mode. + Currently only "readonly" is valid. + + -ignore-remote-version A rare option used for the remote backend only. See + the remote backend documentation for more information. ` return strings.TrimSpace(helpText)