From 1f546214f5dd5172945b49d92e402cf06b37dbe3 Mon Sep 17 00:00:00 2001 From: Chanwit Kaewkasi Date: Fri, 14 Jan 2022 20:51:54 +0700 Subject: [PATCH] fix force-copy Signed-off-by: Chanwit Kaewkasi --- tfexec/init.go | 10 +++++++++- tfexec/init_test.go | 5 ++--- tfexec/terraform_test.go | 2 -- 3 files changed, 11 insertions(+), 6 deletions(-) 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..71fc4c7d 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", diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 7991991b..c755d851 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -708,7 +708,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-lock-timeout=0s", "-backend=true", @@ -740,7 +739,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) { assertCmd(t, []string{ "init", "-no-color", - "-force-copy", "-input=false", "-lock-timeout=0s", "-backend=true",