init: Add godoc comments for `ForceCopy` to mention that it's equivalent to `-migrate-state` in automation (#560)
diff --git a/tfexec/init_test.go b/tfexec/init_test.go index 6f11bab..4e79746 100644 --- a/tfexec/init_test.go +++ b/tfexec/init_test.go
@@ -48,7 +48,24 @@ }) t.Run("override all defaults", func(t *testing.T) { - initCmd, err := tf.initCmd(context.Background(), Backend(false), BackendConfig("confpath1"), BackendConfig("confpath2"), ForceCopy(true), FromModule("testsource"), Get(false), GetPlugins(false), Lock(false), LockTimeout("999s"), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), VerifyPlugins(false), Dir("initdir")) + initCmd, err := tf.initCmd( + context.Background(), + FromModule("testsource"), + LockTimeout("999s"), + Backend(false), + Get(false), + Upgrade(true), + Lock(false), + GetPlugins(false), + VerifyPlugins(false), + ForceCopy(true), + Reconfigure(true), + BackendConfig("confpath1"), + BackendConfig("confpath2"), + PluginDir("testdir1"), + PluginDir("testdir2"), + Dir("initdir"), + ) if err != nil { t.Fatal(err) } @@ -105,7 +122,20 @@ }) t.Run("override all defaults", func(t *testing.T) { - initCmd, err := tf.initCmd(context.Background(), Backend(false), BackendConfig("confpath1"), BackendConfig("confpath2"), FromModule("testsource"), Get(false), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), Dir("initdir")) + initCmd, err := tf.initCmd( + context.Background(), + FromModule("testsource"), + Backend(false), + Get(false), + Upgrade(true), + ForceCopy(true), + Reconfigure(true), + BackendConfig("confpath1"), + BackendConfig("confpath2"), + PluginDir("testdir1"), + PluginDir("testdir2"), + Dir("initdir"), + ) if err != nil { t.Fatal(err) } @@ -118,6 +148,7 @@ "-backend=false", "-get=false", "-upgrade=true", + "-force-copy", "-reconfigure", "-backend-config=confpath1", "-backend-config=confpath2", @@ -158,7 +189,20 @@ }) t.Run("override all defaults", func(t *testing.T) { - initCmd, err := tf.initJSONCmd(context.Background(), Backend(false), BackendConfig("confpath1"), BackendConfig("confpath2"), FromModule("testsource"), Get(false), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), Dir("initdir")) + initCmd, err := tf.initJSONCmd( + context.Background(), + FromModule("testsource"), + Backend(false), + Get(false), + Upgrade(true), + ForceCopy(true), + Reconfigure(true), + BackendConfig("confpath1"), + BackendConfig("confpath2"), + PluginDir("testdir1"), + PluginDir("testdir2"), + Dir("initdir"), + ) if err != nil { t.Fatal(err) } @@ -171,6 +215,7 @@ "-backend=false", "-get=false", "-upgrade=true", + "-force-copy", "-reconfigure", "-backend-config=confpath1", "-backend-config=confpath2",
diff --git a/tfexec/options.go b/tfexec/options.go index 85d2acd..145f10a 100644 --- a/tfexec/options.go +++ b/tfexec/options.go
@@ -168,10 +168,18 @@ return &ForceOption{force} } +// ForceCopyOption represents the `-force-copy` flag for `terraform init`. +// Defaults to false. type ForceCopyOption struct { forceCopy bool } +// ForceCopy returns a ForceCopyOption that indicates whether the init command's -force-copy flag +// should be set to true or false. +// +// Using -force-copy with an init command enables the -migrate-state option but all prompts for +// input are suppressed and automatically answers "yes" to the migration questions. This is an +// alternative to `-migrate-state` when Terraform is running in automation, including via terrform-exec. func ForceCopy(forceCopy bool) *ForceCopyOption { return &ForceCopyOption{forceCopy} }
diff --git a/tfexec/version.go b/tfexec/version.go index cbf28fb..5745ea9 100644 --- a/tfexec/version.go +++ b/tfexec/version.go
@@ -22,6 +22,7 @@ tf0_6_13 = version.Must(version.NewVersion("0.6.13")) tf0_7_7 = version.Must(version.NewVersion("0.7.7")) tf0_8_0 = version.Must(version.NewVersion("0.8.0")) + tf0_9_2 = version.Must(version.NewVersion("0.9.2")) tf0_10_0 = version.Must(version.NewVersion("0.10.0")) tf0_12_0 = version.Must(version.NewVersion("0.12.0")) tf0_13_0 = version.Must(version.NewVersion("0.13.0"))