diff --git a/tfexec/terraform.go b/tfexec/terraform.go index 841660d..0eec6cf 100644 --- a/tfexec/terraform.go +++ b/tfexec/terraform.go @@ -61,19 +61,19 @@ type TerraformCLI interface { // Verison returns a version number of Terraform. Version(ctx context.Context) (string, error) - // Init initializes a given work directory. - Init(ctx context.Context, dir string, opts ...string) error + // Init initializes the current work directory. + Init(ctx context.Context, opts ...string) error // Plan computes expected changes. // If a state is given, use it for the input state. - Plan(ctx context.Context, state *State, dir string, opts ...string) (*Plan, error) + Plan(ctx context.Context, state *State, opts ...string) (*Plan, error) // Apply applies changes. // If a plan is given, use it for the input plan. - Apply(ctx context.Context, plan *Plan, dir string, opts ...string) error + Apply(ctx context.Context, plan *Plan, opts ...string) error // Destroy destroys resources. - Destroy(ctx context.Context, dir string, opts ...string) error + Destroy(ctx context.Context, opts ...string) error // Import imports an existing resource to state. // If a state is given, use it for the input state. @@ -129,7 +129,7 @@ type TerraformCLI interface { OverrideBackendToLocal(ctx context.Context, filename string, workspace string) (func(), error) // PlanHasChange is a helper method which runs plan and return true if the plan has change. - PlanHasChange(ctx context.Context, state *State, dir string, opts ...string) (bool, error) + PlanHasChange(ctx context.Context, state *State, opts ...string) (bool, error) } // terraformCLI implements the TerraformCLI interface. @@ -221,7 +221,7 @@ terraform { } log.Printf("[INFO] [executor@%s] switch backend to local\n", c.Dir()) - err := c.Init(ctx, "", "-input=false", "-no-color", "-reconfigure") + err := c.Init(ctx, "-input=false", "-no-color", "-reconfigure") if err != nil { // remove the override file before return an error. os.Remove(path) @@ -253,7 +253,7 @@ terraform { log.Printf("[ERROR] [executor@%s] please remove the local workspace directory(%s) and re-run terraform init -reconfigure\n", c.Dir(), workspacePath) } log.Printf("[INFO] [executor@%s] switch back to remote\n", c.Dir()) - err = c.Init(ctx, "", "-input=false", "-no-color", "-reconfigure") + err = c.Init(ctx, "-input=false", "-no-color", "-reconfigure") if err != nil { // we cannot return error here. log.Printf("[ERROR] [executor@%s] failed to switch back to remote: %s\n", c.Dir(), err) @@ -265,10 +265,10 @@ terraform { } // PlanHasChange is a helper method which runs plan and return true only if the plan has change. -func (c *terraformCLI) PlanHasChange(ctx context.Context, state *State, dir string, opts ...string) (bool, error) { +func (c *terraformCLI) PlanHasChange(ctx context.Context, state *State, opts ...string) (bool, error) { merged := mergeOptions(opts, []string{"-input=false", "-no-color", "-detailed-exitcode"}) - _, err := c.Plan(ctx, state, dir, merged...) + _, err := c.Plan(ctx, state, merged...) if err != nil { if exitErr, ok := err.(ExitError); ok && exitErr.ExitCode() == 2 { return true, nil diff --git a/tfexec/terraform_apply.go b/tfexec/terraform_apply.go index b977b87..85ab8b9 100644 --- a/tfexec/terraform_apply.go +++ b/tfexec/terraform_apply.go @@ -2,20 +2,16 @@ package tfexec import ( "context" - "fmt" "os" ) // Apply applies changes. // If a plan is given, use it for the input plan. -func (c *terraformCLI) Apply(ctx context.Context, plan *Plan, dir string, opts ...string) error { +func (c *terraformCLI) Apply(ctx context.Context, plan *Plan, opts ...string) error { args := []string{"apply"} args = append(args, opts...) if plan != nil { - if len(dir) > 0 { - return fmt.Errorf("failed to build options. The plan argument (!= nil) and the dir argument cannot be set at the same time: plan=%v, dir=%v", plan, dir) - } tmpPlan, err := writeTempFile(plan.Bytes()) defer os.Remove(tmpPlan.Name()) if err != nil { @@ -24,10 +20,6 @@ func (c *terraformCLI) Apply(ctx context.Context, plan *Plan, dir string, opts . args = append(args, tmpPlan.Name()) } - if len(dir) > 0 { - args = append(args, dir) - } - _, _, err := c.Run(ctx, args...) return err diff --git a/tfexec/terraform_apply_test.go b/tfexec/terraform_apply_test.go index f68337b..7abd27a 100644 --- a/tfexec/terraform_apply_test.go +++ b/tfexec/terraform_apply_test.go @@ -14,12 +14,11 @@ func TestTerraformCLIApply(t *testing.T) { desc string mockCommands []*mockCommand plan *Plan - dir string opts []string ok bool }{ { - desc: "no dir and no opts", + desc: "no opts", mockCommands: []*mockCommand{ { args: []string{"terraform", "apply"}, @@ -38,17 +37,6 @@ func TestTerraformCLIApply(t *testing.T) { }, ok: false, }, - { - desc: "with dir", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "apply", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - ok: true, - }, { desc: "with opts", mockCommands: []*mockCommand{ @@ -60,18 +48,6 @@ func TestTerraformCLIApply(t *testing.T) { opts: []string{"-input=false", "-no-color"}, ok: true, }, - { - desc: "with dir and opts", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "apply", "-input=false", "-no-color", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - opts: []string{"-input=false", "-no-color"}, - ok: true, - }, { desc: "with plan", mockCommands: []*mockCommand{ @@ -85,27 +61,13 @@ func TestTerraformCLIApply(t *testing.T) { opts: []string{"-input=false", "-no-color"}, ok: true, }, - { - desc: "with plan and dir (conflict error)", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "apply", "-input=false", "-no-color", "/path/to/planfile", "foo"}, - argsRe: regexp.MustCompile(`^terraform apply -input=false -no-color \S+ foo$`), - exitCode: 0, - }, - }, - plan: plan, - dir: "foo", - opts: []string{"-input=false", "-state=foo.tfstate"}, - ok: false, - }, } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { e := NewMockExecutor(tc.mockCommands) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Apply(context.Background(), tc.plan, tc.dir, tc.opts...) + err := terraformCLI.Apply(context.Background(), tc.plan, tc.opts...) if tc.ok && err != nil { t.Fatalf("unexpected err: %s", err) } @@ -123,17 +85,17 @@ func TestAccTerraformCLIApply(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - plan, err := terraformCLI.Plan(context.Background(), nil, "", "-input=false", "-no-color") + plan, err := terraformCLI.Plan(context.Background(), nil, "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform plan: %s", err) } - err = terraformCLI.Apply(context.Background(), plan, "", "-input=false", "-no-color") + err = terraformCLI.Apply(context.Background(), plan, "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_destroy.go b/tfexec/terraform_destroy.go index c2dce71..d24929c 100644 --- a/tfexec/terraform_destroy.go +++ b/tfexec/terraform_destroy.go @@ -3,12 +3,9 @@ package tfexec import "context" // Destroy destroys resources. -func (c *terraformCLI) Destroy(ctx context.Context, dir string, opts ...string) error { +func (c *terraformCLI) Destroy(ctx context.Context, opts ...string) error { args := []string{"destroy"} args = append(args, opts...) - if len(dir) > 0 { - args = append(args, dir) - } _, _, err := c.Run(ctx, args...) return err } diff --git a/tfexec/terraform_destroy_test.go b/tfexec/terraform_destroy_test.go index 203b9e6..c63f9d6 100644 --- a/tfexec/terraform_destroy_test.go +++ b/tfexec/terraform_destroy_test.go @@ -9,12 +9,11 @@ func TestTerraformCLIDestroy(t *testing.T) { cases := []struct { desc string mockCommands []*mockCommand - dir string opts []string ok bool }{ { - desc: "no dir and no opts", + desc: "no opts", mockCommands: []*mockCommand{ { args: []string{"terraform", "destroy"}, @@ -33,17 +32,6 @@ func TestTerraformCLIDestroy(t *testing.T) { }, ok: false, }, - { - desc: "with dir", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "destroy", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - ok: true, - }, { desc: "with opts", mockCommands: []*mockCommand{ @@ -55,25 +43,13 @@ func TestTerraformCLIDestroy(t *testing.T) { opts: []string{"-input=false", "-no-color"}, ok: true, }, - { - desc: "with dir and opts", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "destroy", "-input=false", "-no-color", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - opts: []string{"-input=false", "-no-color"}, - ok: true, - }, } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { e := NewMockExecutor(tc.mockCommands) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Destroy(context.Background(), tc.dir, tc.opts...) + err := terraformCLI.Destroy(context.Background(), tc.opts...) if tc.ok && err != nil { t.Fatalf("unexpected err: %s", err) } @@ -91,17 +67,17 @@ func TestAccTerraformCLIDestroy(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } - err = terraformCLI.Destroy(context.Background(), "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Destroy(context.Background(), "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform destroy: %s", err) } diff --git a/tfexec/terraform_import_test.go b/tfexec/terraform_import_test.go index ef48018..ba4017e 100644 --- a/tfexec/terraform_import_test.go +++ b/tfexec/terraform_import_test.go @@ -163,12 +163,12 @@ func TestAccTerraformCLIImport(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - _, err = terraformCLI.Plan(context.Background(), nil, "", "-input=false", "-no-color", "-detailed-exitcode") + _, err = terraformCLI.Plan(context.Background(), nil, "-input=false", "-no-color", "-detailed-exitcode") if err != nil { if exitErr, ok := err.(*exitError); ok { if exitErr.ExitCode() != 2 { @@ -196,7 +196,7 @@ func TestAccTerraformCLIImport(t *testing.T) { t.Errorf("got: %v, want: %v", got, want) } - _, err = terraformCLI.Plan(context.Background(), state, "", "-input=false", "-no-color", "-detailed-exitcode") + _, err = terraformCLI.Plan(context.Background(), state, "-input=false", "-no-color", "-detailed-exitcode") if err != nil { t.Fatalf("failed to run terraform plan after import (expected no diff): %s", err) } diff --git a/tfexec/terraform_init.go b/tfexec/terraform_init.go index 5bc57ad..523093f 100644 --- a/tfexec/terraform_init.go +++ b/tfexec/terraform_init.go @@ -2,13 +2,10 @@ package tfexec import "context" -// Init initializes a given work directory. -func (c *terraformCLI) Init(ctx context.Context, dir string, opts ...string) error { +// Init initializes the current work directory. +func (c *terraformCLI) Init(ctx context.Context, opts ...string) error { args := []string{"init"} args = append(args, opts...) - if len(dir) > 0 { - args = append(args, dir) - } _, _, err := c.Run(ctx, args...) return err } diff --git a/tfexec/terraform_init_test.go b/tfexec/terraform_init_test.go index e8db312..9f5a9c1 100644 --- a/tfexec/terraform_init_test.go +++ b/tfexec/terraform_init_test.go @@ -11,12 +11,11 @@ func TestTerraformCLIInit(t *testing.T) { cases := []struct { desc string mockCommands []*mockCommand - dir string opts []string ok bool }{ { - desc: "no dir and no opts", + desc: "no opts", mockCommands: []*mockCommand{ { args: []string{"terraform", "init"}, @@ -35,17 +34,6 @@ func TestTerraformCLIInit(t *testing.T) { }, ok: false, }, - { - desc: "with dir", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "init", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - ok: true, - }, { desc: "with opts", mockCommands: []*mockCommand{ @@ -57,25 +45,13 @@ func TestTerraformCLIInit(t *testing.T) { opts: []string{"-input=false", "-no-color"}, ok: true, }, - { - desc: "with dir and opts", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "init", "-input=false", "-no-color", "foo"}, - exitCode: 0, - }, - }, - dir: "foo", - opts: []string{"-input=false", "-no-color"}, - ok: true, - }, } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { e := NewMockExecutor(tc.mockCommands) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), tc.dir, tc.opts...) + err := terraformCLI.Init(context.Background(), tc.opts...) if tc.ok && err != nil { t.Fatalf("unexpected err: %s", err) } @@ -93,7 +69,7 @@ func TestAccTerraformCLIInit(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } diff --git a/tfexec/terraform_plan.go b/tfexec/terraform_plan.go index 7c88f6d..46992b5 100644 --- a/tfexec/terraform_plan.go +++ b/tfexec/terraform_plan.go @@ -9,7 +9,7 @@ import ( // Plan computes expected changes. // If a state is given, use it for the input state. -func (c *terraformCLI) Plan(ctx context.Context, state *State, dir string, opts ...string) (*Plan, error) { +func (c *terraformCLI) Plan(ctx context.Context, state *State, opts ...string) (*Plan, error) { args := []string{"plan"} if state != nil { @@ -45,10 +45,6 @@ func (c *terraformCLI) Plan(ctx context.Context, state *State, dir string, opts args = append(args, opts...) - if len(dir) > 0 { - args = append(args, dir) - } - _, _, err := c.Run(ctx, args...) // terraform plan -detailed-exitcode returns 2 if there is a diff. diff --git a/tfexec/terraform_plan_test.go b/tfexec/terraform_plan_test.go index 08f507f..8c0540a 100644 --- a/tfexec/terraform_plan_test.go +++ b/tfexec/terraform_plan_test.go @@ -31,13 +31,12 @@ func TestTerraformCLIPlan(t *testing.T) { desc string mockCommands []*mockCommand state *State - dir string opts []string want *Plan ok bool }{ { - desc: "no dir and no opts", + desc: "no opts", mockCommands: []*mockCommand{ { args: []string{"terraform", "plan", "-out=/path/to/planfile"}, @@ -63,21 +62,6 @@ func TestTerraformCLIPlan(t *testing.T) { want: NewPlan([]byte{}), ok: false, }, - { - desc: "with dir", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "plan", "-out=/path/to/planfile", "foo"}, - argsRe: regexp.MustCompile(`^terraform plan -out=.+ foo$`), - runFunc: runFunc, - exitCode: 0, - }, - }, - dir: "foo", - state: nil, - want: plan, - ok: true, - }, { desc: "with opts", mockCommands: []*mockCommand{ @@ -93,33 +77,16 @@ func TestTerraformCLIPlan(t *testing.T) { want: plan, ok: true, }, - { - desc: "with dir and opts", - mockCommands: []*mockCommand{ - { - args: []string{"terraform", "plan", "-out=/path/to/planfile", "-input=false", "-no-color", "foo"}, - argsRe: regexp.MustCompile(`^terraform plan -out=.+ -input=false -no-color foo$`), - runFunc: runFunc, - exitCode: 0, - }, - }, - dir: "foo", - opts: []string{"-input=false", "-no-color"}, - state: nil, - want: plan, - ok: true, - }, { desc: "with state", mockCommands: []*mockCommand{ { - args: []string{"terraform", "plan", "-state=/path/to/tempfile", "-out=/path/to/planfile", "-input=false", "-no-color", "foo"}, - argsRe: regexp.MustCompile(`^terraform plan -state=.+ -out=.+ -input=false -no-color foo$`), + args: []string{"terraform", "plan", "-state=/path/to/tempfile", "-out=/path/to/planfile", "-input=false", "-no-color"}, + argsRe: regexp.MustCompile(`^terraform plan -state=.+ -out=.+ -input=false -no-color$`), runFunc: runFunc, exitCode: 0, }, }, - dir: "foo", opts: []string{"-input=false", "-no-color"}, state: state, want: plan, @@ -129,13 +96,12 @@ func TestTerraformCLIPlan(t *testing.T) { desc: "with state and -state= (conflict error)", mockCommands: []*mockCommand{ { - args: []string{"terraform", "plan", "-state=/path/to/tempfile", "-out=/path/to/planfile", "-input=false", "-state=foo.tfstate", "foo"}, - argsRe: regexp.MustCompile(`^terraform plan -state=\S+ -out=.+ -input=false -no-color -state=foo.tfstate foo$`), + args: []string{"terraform", "plan", "-state=/path/to/tempfile", "-out=/path/to/planfile", "-input=false", "-state=foo.tfstate"}, + argsRe: regexp.MustCompile(`^terraform plan -state=\S+ -out=.+ -input=false -no-color -state=foo.tfstate$`), runFunc: runFunc, exitCode: 0, }, }, - dir: "foo", opts: []string{"-input=false", "-state=foo.tfstate"}, state: state, want: nil, @@ -147,7 +113,7 @@ func TestTerraformCLIPlan(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { e := NewMockExecutor(tc.mockCommands) terraformCLI := NewTerraformCLI(e) - got, err := terraformCLI.Plan(context.Background(), tc.state, tc.dir, tc.opts...) + got, err := terraformCLI.Plan(context.Background(), tc.state, tc.opts...) if tc.ok && err != nil { t.Fatalf("unexpected err: %s", err) } @@ -168,12 +134,12 @@ func TestAccTerraformCLIPlan(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - plan, err := terraformCLI.Plan(context.Background(), nil, "", "-input=false", "-no-color") + plan, err := terraformCLI.Plan(context.Background(), nil, "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform plan: %s", err) } @@ -190,13 +156,13 @@ func TestAccTerraformCLIPlanWithOut(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } planOut := "foo.tfplan" - plan, err := terraformCLI.Plan(context.Background(), nil, "", "-input=false", "-no-color", "-out="+planOut) + plan, err := terraformCLI.Plan(context.Background(), nil, "-input=false", "-no-color", "-out="+planOut) if err != nil { t.Fatalf("failed to run terraform plan: %s", err) } diff --git a/tfexec/terraform_state_list_test.go b/tfexec/terraform_state_list_test.go index 823a32a..c49db63 100644 --- a/tfexec/terraform_state_list_test.go +++ b/tfexec/terraform_state_list_test.go @@ -165,12 +165,12 @@ resource "null_resource" "bar" {} e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_state_mv_test.go b/tfexec/terraform_state_mv_test.go index ae1d541..4547778 100644 --- a/tfexec/terraform_state_mv_test.go +++ b/tfexec/terraform_state_mv_test.go @@ -240,12 +240,12 @@ resource "null_resource" "bar" {} e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } @@ -283,12 +283,12 @@ resource "null_resource" "bar" {} e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_state_pull_test.go b/tfexec/terraform_state_pull_test.go index aac490d..769994e 100644 --- a/tfexec/terraform_state_pull_test.go +++ b/tfexec/terraform_state_pull_test.go @@ -78,12 +78,12 @@ func TestAccTerraformCLIStatePull(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_state_push_test.go b/tfexec/terraform_state_push_test.go index 76449c1..4ba4ef2 100644 --- a/tfexec/terraform_state_push_test.go +++ b/tfexec/terraform_state_push_test.go @@ -79,12 +79,12 @@ func TestAccTerraformCLIStatePush(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_state_rm_test.go b/tfexec/terraform_state_rm_test.go index 0ed4475..c337a8f 100644 --- a/tfexec/terraform_state_rm_test.go +++ b/tfexec/terraform_state_rm_test.go @@ -152,12 +152,12 @@ resource "null_resource" "bar" {} e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 1d3d29c..1b64d3a 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -107,7 +107,7 @@ resource "aws_security_group" "bar" {} ` UpdateTestAccSource(t, terraformCLI, backend+updatedSource) - changed, err := terraformCLI.PlanHasChange(context.Background(), nil, "") + changed, err := terraformCLI.PlanHasChange(context.Background(), nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -139,7 +139,7 @@ resource "aws_security_group" "bar" {} t.Fatalf("failed to run terraform state mv: %s", err) } - changed, err = terraformCLI.PlanHasChange(context.Background(), updatedState, "") + changed, err = terraformCLI.PlanHasChange(context.Background(), updatedState) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -153,7 +153,7 @@ resource "aws_security_group" "bar" {} t.Fatalf("the override file wasn't removed: %s", err) } - changed, err = terraformCLI.PlanHasChange(context.Background(), nil, "") + changed, err = terraformCLI.PlanHasChange(context.Background(), nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -169,12 +169,12 @@ func TestAccTerraformCLIPlanHasChange(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } - changed, err := terraformCLI.PlanHasChange(context.Background(), nil, "") + changed, err := terraformCLI.PlanHasChange(context.Background(), nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -182,12 +182,12 @@ func TestAccTerraformCLIPlanHasChange(t *testing.T) { t.Fatalf("expect not to have changes") } - err = terraformCLI.Apply(context.Background(), nil, "", "-input=false", "-no-color", "-auto-approve") + err = terraformCLI.Apply(context.Background(), nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } - changed, err = terraformCLI.PlanHasChange(context.Background(), nil, "") + changed, err = terraformCLI.PlanHasChange(context.Background(), nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } diff --git a/tfexec/terraform_workspace_new_test.go b/tfexec/terraform_workspace_new_test.go index 607b698..2e18bda 100644 --- a/tfexec/terraform_workspace_new_test.go +++ b/tfexec/terraform_workspace_new_test.go @@ -69,7 +69,7 @@ func TestAccTerraformCLIWorkspaceNew(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } diff --git a/tfexec/terraform_workspace_select_test.go b/tfexec/terraform_workspace_select_test.go index e3befce..905fe26 100644 --- a/tfexec/terraform_workspace_select_test.go +++ b/tfexec/terraform_workspace_select_test.go @@ -67,7 +67,7 @@ func TestAccTerraformCLIWorkspaceSelect(t *testing.T) { e := SetupTestAcc(t, source) terraformCLI := NewTerraformCLI(e) - err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color") + err := terraformCLI.Init(context.Background(), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } diff --git a/tfexec/test_helper.go b/tfexec/test_helper.go index e783c95..4af09d0 100644 --- a/tfexec/test_helper.go +++ b/tfexec/test_helper.go @@ -291,7 +291,7 @@ func SetupTestAccWithApply(t *testing.T, workspace string, source string) Terraf tf := NewTerraformCLI(e) ctx := context.Background() - err := tf.Init(ctx, "", "-input=false", "-no-color") + err := tf.Init(ctx, "-input=false", "-no-color") if err != nil { t.Fatalf("failed to run terraform init: %s", err) } @@ -304,14 +304,14 @@ func SetupTestAccWithApply(t *testing.T, workspace string, source string) Terraf } } - err = tf.Apply(ctx, nil, "", "-input=false", "-no-color", "-auto-approve") + err = tf.Apply(ctx, nil, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform apply: %s", err) } // destroy resources after each test not to have any state. t.Cleanup(func() { - err := tf.Destroy(ctx, "", "-input=false", "-no-color", "-auto-approve") + err := tf.Destroy(ctx, "-input=false", "-no-color", "-auto-approve") if err != nil { t.Fatalf("failed to run terraform destroy: %s", err) } diff --git a/tfmigrate/migrator.go b/tfmigrate/migrator.go index c31ba1b..8ceb051 100644 --- a/tfmigrate/migrator.go +++ b/tfmigrate/migrator.go @@ -32,7 +32,7 @@ func setupWorkDir(ctx context.Context, tf tfexec.TerraformCLI, workspace string) // init folder log.Printf("[INFO] [migrator@%s] initialize work dir\n", tf.Dir()) - err = tf.Init(ctx, "", "-input=false", "-no-color") + err = tf.Init(ctx, "-input=false", "-no-color") if err != nil { return nil, nil, err } diff --git a/tfmigrate/multi_state_migrator.go b/tfmigrate/multi_state_migrator.go index c05370b..d3bb35d 100644 --- a/tfmigrate/multi_state_migrator.go +++ b/tfmigrate/multi_state_migrator.go @@ -140,7 +140,7 @@ func (m *MultiStateMigrator) plan(ctx context.Context) (*tfexec.State, *tfexec.S // check if a plan in fromDir has no changes. log.Printf("[INFO] [migrator@%s] check diffs\n", m.fromTf.Dir()) - _, err = m.fromTf.Plan(ctx, fromCurrentState, "", planOpts...) + _, err = m.fromTf.Plan(ctx, fromCurrentState, planOpts...) if err != nil { if exitErr, ok := err.(tfexec.ExitError); ok && exitErr.ExitCode() == 2 { if m.force { @@ -155,7 +155,7 @@ func (m *MultiStateMigrator) plan(ctx context.Context) (*tfexec.State, *tfexec.S // check if a plan in toDir has no changes. log.Printf("[INFO] [migrator@%s] check diffs\n", m.toTf.Dir()) - _, err = m.toTf.Plan(ctx, toCurrentState, "", planOpts...) + _, err = m.toTf.Plan(ctx, toCurrentState, planOpts...) if err != nil { if exitErr, ok := err.(tfexec.ExitError); ok && exitErr.ExitCode() == 2 { if m.force { diff --git a/tfmigrate/multi_state_migrator_test.go b/tfmigrate/multi_state_migrator_test.go index b9a7c68..ee19ef2 100644 --- a/tfmigrate/multi_state_migrator_test.go +++ b/tfmigrate/multi_state_migrator_test.go @@ -250,14 +250,14 @@ func TestAccMultiStateMigratorApply(t *testing.T) { //update terraform resource files for migration tfexec.UpdateTestAccSource(t, fromTf, fromBackend+tc.fromUpdatedSource) tfexec.UpdateTestAccSource(t, toTf, toBackend+tc.toUpdatedSource) - changed, err := fromTf.PlanHasChange(ctx, nil, "") + changed, err := fromTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in fromDir: %s", err) } if !changed { t.Fatalf("expect to have changes in fromDir") } - changed, err = toTf.PlanHasChange(ctx, nil, "") + changed, err = toTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in toDir: %s", err) } @@ -310,14 +310,14 @@ func TestAccMultiStateMigratorApply(t *testing.T) { if !reflect.DeepEqual(toGot, tc.toUpdatedState) { t.Errorf("got state: %v, want state: %v in toDir", toGot, tc.toUpdatedState) } - changed, err = fromTf.PlanHasChange(ctx, nil, "") + changed, err = fromTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in fromDir: %s", err) } if changed != tc.fromStateExpectChange { t.Fatalf("expected change in fromDir is %t but actual value is %t", tc.fromStateExpectChange, changed) } - changed, err = toTf.PlanHasChange(ctx, nil, "") + changed, err = toTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in toDir: %s", err) } @@ -331,7 +331,7 @@ func TestAccMultiStateMigratorApply(t *testing.T) { if err != nil { t.Fatalf("failed to read a saved plan file in fromDir: %s", err) } - err = fromTf.Apply(ctx, tfexec.NewPlan(fromPlan), "", "-input=false", "-no-color") + err = fromTf.Apply(ctx, tfexec.NewPlan(fromPlan), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to apply the saved plan file in fromDir: %s", err) } @@ -339,7 +339,7 @@ func TestAccMultiStateMigratorApply(t *testing.T) { if err != nil { t.Fatalf("failed to read a saved plan file in toDir: %s", err) } - err = toTf.Apply(ctx, tfexec.NewPlan(toPlan), "", "-input=false", "-no-color") + err = toTf.Apply(ctx, tfexec.NewPlan(toPlan), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to apply the saved plan file in toDir: %s", err) } @@ -382,14 +382,14 @@ func TestAccMultiStateMigratorApply(t *testing.T) { } // confirm no changes - changed, err := fromTf.PlanHasChange(ctx, nil, "") + changed, err := fromTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in fromDir: %s", err) } if changed { t.Fatalf("expect not to have changes in fromDir") } - changed, err = toTf.PlanHasChange(ctx, nil, "") + changed, err = toTf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange in toDir: %s", err) } diff --git a/tfmigrate/state_import_action_test.go b/tfmigrate/state_import_action_test.go index 5af0b1e..3df401f 100644 --- a/tfmigrate/state_import_action_test.go +++ b/tfmigrate/state_import_action_test.go @@ -31,7 +31,7 @@ resource "aws_iam_user" "baz" { t.Fatalf("failed to run terraform state rm: %s", err) } - changed, err := tf.PlanHasChange(ctx, nil, "") + changed, err := tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } diff --git a/tfmigrate/state_migrator.go b/tfmigrate/state_migrator.go index 88e185f..4d5abbb 100644 --- a/tfmigrate/state_migrator.go +++ b/tfmigrate/state_migrator.go @@ -119,7 +119,7 @@ func (m *StateMigrator) plan(ctx context.Context) (*tfexec.State, error) { } log.Printf("[INFO] [migrator@%s] check diffs\n", m.tf.Dir()) - _, err = m.tf.Plan(ctx, currentState, "", planOpts...) + _, err = m.tf.Plan(ctx, currentState, planOpts...) if err != nil { if exitErr, ok := err.(tfexec.ExitError); ok && exitErr.ExitCode() == 2 { if m.force { diff --git a/tfmigrate/state_migrator_test.go b/tfmigrate/state_migrator_test.go index c856f74..aa0d67f 100644 --- a/tfmigrate/state_migrator_test.go +++ b/tfmigrate/state_migrator_test.go @@ -134,7 +134,7 @@ resource "aws_iam_user" "qux" { t.Fatalf("failed to run terraform state rm: %s", err) } - changed, err := tf.PlanHasChange(ctx, nil, "") + changed, err := tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -175,7 +175,7 @@ resource "aws_iam_user" "qux" { t.Errorf("got state: %v, want state: %v", got, want) } - changed, err = tf.PlanHasChange(ctx, nil, "") + changed, err = tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -204,7 +204,7 @@ resource "aws_security_group" "baz" {} tfexec.UpdateTestAccSource(t, tf, backend+updatedSource) - changed, err := tf.PlanHasChange(ctx, nil, "") + changed, err := tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -245,7 +245,7 @@ resource "aws_security_group" "baz" {} t.Errorf("got state: %v, want state: %v", got, want) } - changed, err = tf.PlanHasChange(ctx, nil, "") + changed, err = tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } @@ -258,7 +258,7 @@ resource "aws_security_group" "baz" {} if err != nil { t.Fatalf("failed to read a saved plan file: %s", err) } - err = tf.Apply(ctx, tfexec.NewPlan(plan), "", "-input=false", "-no-color") + err = tf.Apply(ctx, tfexec.NewPlan(plan), "-input=false", "-no-color") if err != nil { t.Fatalf("failed to apply the saved plan file: %s", err) } @@ -286,7 +286,7 @@ resource "aws_security_group" "baz" {} } // confirm no changes - changed, err = tf.PlanHasChange(ctx, nil, "") + changed, err = tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } diff --git a/tfmigrate/state_mv_action_test.go b/tfmigrate/state_mv_action_test.go index 3aa5878..1a164b1 100644 --- a/tfmigrate/state_mv_action_test.go +++ b/tfmigrate/state_mv_action_test.go @@ -28,7 +28,7 @@ resource "aws_security_group" "baz" {} tfexec.UpdateTestAccSource(t, tf, backend+updatedSource) - changed, err := tf.PlanHasChange(ctx, nil, "") + changed, err := tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) } diff --git a/tfmigrate/state_rm_action_test.go b/tfmigrate/state_rm_action_test.go index dd7ef16..caa6997 100644 --- a/tfmigrate/state_rm_action_test.go +++ b/tfmigrate/state_rm_action_test.go @@ -27,7 +27,7 @@ resource "aws_security_group" "baz" {} tfexec.UpdateTestAccSource(t, tf, backend+updatedSource) - changed, err := tf.PlanHasChange(ctx, nil, "") + changed, err := tf.PlanHasChange(ctx, nil) if err != nil { t.Fatalf("failed to run PlanHasChange: %s", err) }