Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 2 additions & 5 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 Expand Up @@ -95,7 +94,6 @@ func TestInitCmd_v1(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand All @@ -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",
Expand Down
17 changes: 0 additions & 17 deletions tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func TestSetLog(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -155,7 +154,6 @@ func TestSetLog(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -193,7 +191,6 @@ func TestSetLog(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -262,7 +259,6 @@ func TestSetLogCore(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -300,7 +296,6 @@ func TestSetLogCore(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -338,7 +333,6 @@ func TestSetLogCore(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -381,7 +375,6 @@ func TestSetLogPath(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -413,7 +406,6 @@ func TestSetLogPath(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -463,7 +455,6 @@ func TestSetLogPath(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -513,7 +504,6 @@ func TestSetLogPath(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -582,7 +572,6 @@ func TestSetLogProvider(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -620,7 +609,6 @@ func TestSetLogProvider(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down Expand Up @@ -658,7 +646,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 +695,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 +726,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 +772,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 +799,6 @@ func TestCheckpointDisablePropagation_v1(t *testing.T) {
assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
Expand Down