Skip to content

Commit

Permalink
fix force-copy
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
  • Loading branch information
chanwit committed Aug 12, 2022
1 parent 495b9eb commit 229a909
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 9 additions & 1 deletion tfexec/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions tfexec/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -46,15 +45,14 @@ 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)
}

assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-from-module=testsource",
"-lock-timeout=999s",
Expand All @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ func TestSetLogProvider(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -708,7 +707,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-lock-timeout=0s",
"-backend=true",
Expand Down Expand Up @@ -740,7 +738,6 @@ func TestCheckpointDisablePropagation_v012(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-lock-timeout=0s",
"-backend=true",
Expand Down Expand Up @@ -787,7 +784,6 @@ func TestCheckpointDisablePropagation_v1(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -815,7 +811,6 @@ func TestCheckpointDisablePropagation_v1(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down

0 comments on commit 229a909

Please sign in to comment.