Skip to content

Commit 1f54621

Browse files
committed
fix force-copy
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
1 parent 495b9eb commit 1f54621

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

tfexec/init.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (opt *DirOption) configureInit(conf *initConfig) {
5252
conf.dir = opt.path
5353
}
5454

55+
func (opt *ForceCopyOption) configureInit(conf *initConfig) {
56+
conf.forceCopy = opt.forceCopy
57+
}
58+
5559
func (opt *FromModuleOption) configureInit(conf *initConfig) {
5660
conf.fromModule = opt.source
5761
}
@@ -116,7 +120,7 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd
116120
o.configureInit(&c)
117121
}
118122

119-
args := []string{"init", "-no-color", "-force-copy", "-input=false"}
123+
args := []string{"init", "-no-color", "-input=false"}
120124

121125
// string opts: only pass if set
122126
if c.fromModule != "" {
@@ -144,6 +148,10 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd
144148
args = append(args, "-verify-plugins="+fmt.Sprint(c.verifyPlugins))
145149
}
146150

151+
if c.forceCopy {
152+
args = append(args, "-force-copy")
153+
}
154+
147155
// unary flags: pass if true
148156
if c.reconfigure {
149157
args = append(args, "-reconfigure")

tfexec/init_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestInitCmd_v012(t *testing.T) {
3333
assertCmd(t, []string{
3434
"init",
3535
"-no-color",
36-
"-force-copy",
3736
"-input=false",
3837
"-lock-timeout=0s",
3938
"-backend=true",
@@ -46,15 +45,14 @@ func TestInitCmd_v012(t *testing.T) {
4645
})
4746

4847
t.Run("override all defaults", func(t *testing.T) {
49-
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"))
48+
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"))
5049
if err != nil {
5150
t.Fatal(err)
5251
}
5352

5453
assertCmd(t, []string{
5554
"init",
5655
"-no-color",
57-
"-force-copy",
5856
"-input=false",
5957
"-from-module=testsource",
6058
"-lock-timeout=999s",
@@ -64,6 +62,7 @@ func TestInitCmd_v012(t *testing.T) {
6462
"-lock=false",
6563
"-get-plugins=false",
6664
"-verify-plugins=false",
65+
"-force-copy",
6766
"-reconfigure",
6867
"-backend-config=confpath1",
6968
"-backend-config=confpath2",

tfexec/terraform_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) {
708708
assertCmd(t, []string{
709709
"init",
710710
"-no-color",
711-
"-force-copy",
712711
"-input=false",
713712
"-lock-timeout=0s",
714713
"-backend=true",
@@ -740,7 +739,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) {
740739
assertCmd(t, []string{
741740
"init",
742741
"-no-color",
743-
"-force-copy",
744742
"-input=false",
745743
"-lock-timeout=0s",
746744
"-backend=true",

0 commit comments

Comments
 (0)