diff --git a/tfexec/init.go b/tfexec/init.go index bff9ecd3..8fd36677 100644 --- a/tfexec/init.go +++ b/tfexec/init.go @@ -52,6 +52,10 @@ func (opt *DirOption) configureInit(conf *initConfig) { conf.dir = opt.path } +func (opt *ForceCopyOption) configureInit(conf *initConfig) { + conf.forceCopy = opt.forceCopy +} + func (opt *FromModuleOption) configureInit(conf *initConfig) { conf.fromModule = opt.source } @@ -116,7 +120,7 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd o.configureInit(&c) } - args := []string{"init", "-no-color", "-force-copy", "-input=false"} + args := []string{"init", "-no-color", "-input=false"} // string opts: only pass if set if c.fromModule != "" { @@ -144,6 +148,10 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd args = append(args, "-verify-plugins="+fmt.Sprint(c.verifyPlugins)) } + if c.forceCopy { + args = append(args, "-force-copy") + } + // unary flags: pass if true if c.reconfigure { args = append(args, "-reconfigure") diff --git a/tfexec/init_test.go b/tfexec/init_test.go index 850f36f8..4d1a7fd1 100644 --- a/tfexec/init_test.go +++ b/tfexec/init_test.go @@ -33,7 +33,6 @@ func TestInitCmd_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-lock-timeout=0s", "-backend=true", @@ -46,7 +45,7 @@ func TestInitCmd_v012(t *testing.T) { }) 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), GetPlugins(false), Lock(false), LockTimeout("999s"), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), VerifyPlugins(false), Dir("initdir")) + 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")) if err != nil { t.Fatal(err) } @@ -54,7 +53,6 @@ func TestInitCmd_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-from-module=testsource", "-lock-timeout=999s", @@ -64,6 +62,7 @@ func TestInitCmd_v012(t *testing.T) { "-lock=false", "-get-plugins=false", "-verify-plugins=false", + "-force-copy", "-reconfigure", "-backend-config=confpath1", "-backend-config=confpath2", @@ -95,7 +94,6 @@ func TestInitCmd_v1(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -112,7 +110,6 @@ func TestInitCmd_v1(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-from-module=testsource", "-backend=false", diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 7991991b..79338ea8 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -117,7 +117,6 @@ func TestSetLog(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -155,7 +154,6 @@ func TestSetLog(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -193,7 +191,6 @@ func TestSetLog(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -262,7 +259,6 @@ func TestSetLogCore(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -300,7 +296,6 @@ func TestSetLogCore(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -338,7 +333,6 @@ func TestSetLogCore(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -381,7 +375,6 @@ func TestSetLogPath(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -413,7 +406,6 @@ func TestSetLogPath(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -463,7 +455,6 @@ func TestSetLogPath(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -513,7 +504,6 @@ func TestSetLogPath(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -582,7 +572,6 @@ func TestSetLogProvider(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -620,7 +609,6 @@ func TestSetLogProvider(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -658,7 +646,6 @@ func TestSetLogProvider(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -708,7 +695,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-lock-timeout=0s", "-backend=true", @@ -740,7 +726,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-lock-timeout=0s", "-backend=true", @@ -787,7 +772,6 @@ func TestCheckpointDisablePropagation_v1(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true", @@ -815,7 +799,6 @@ func TestCheckpointDisablePropagation_v1(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-backend=true", "-get=true",