From c3dfa63c374576de5c6cf48850ab35162b464db2 Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Tue, 25 Aug 2020 15:01:02 -0400 Subject: [PATCH] Support multiple VarFile options Fixes #33 --- tfexec/apply.go | 10 +++++----- tfexec/apply_test.go | 6 ++++-- tfexec/destroy.go | 10 +++++----- tfexec/import.go | 8 ++++---- tfexec/plan.go | 8 ++++---- tfexec/refresh.go | 8 ++++---- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/tfexec/apply.go b/tfexec/apply.go index 1250413a..37311bec 100644 --- a/tfexec/apply.go +++ b/tfexec/apply.go @@ -21,8 +21,8 @@ type applyConfig struct { targets []string // Vars: each var must be supplied as a single string, e.g. 'foo=bar' - vars []string - varFile string + vars []string + varFiles []string } var defaultApplyOptions = applyConfig{ @@ -60,7 +60,7 @@ func (opt *StateOutOption) configureApply(conf *applyConfig) { } func (opt *VarFileOption) configureApply(conf *applyConfig) { - conf.varFile = opt.path + conf.varFiles = append(conf.varFiles, opt.path) } func (opt *LockOption) configureApply(conf *applyConfig) { @@ -105,8 +105,8 @@ func (tf *Terraform) applyCmd(ctx context.Context, opts ...ApplyOption) *exec.Cm if c.stateOut != "" { args = append(args, "-state-out="+c.stateOut) } - if c.varFile != "" { - args = append(args, "-var-file="+c.varFile) + for _, vf := range c.varFiles { + args = append(args, "-var-file="+vf) } // boolean and numerical opts: always pass diff --git a/tfexec/apply_test.go b/tfexec/apply_test.go index 4d1f33b6..38e78785 100644 --- a/tfexec/apply_test.go +++ b/tfexec/apply_test.go @@ -26,7 +26,8 @@ func TestApplyCmd(t *testing.T) { LockTimeout("200s"), State("teststate"), StateOut("teststateout"), - VarFile("testvarfile"), + VarFile("foo.tfvars"), + VarFile("bar.tfvars"), Lock(false), Parallelism(99), Refresh(false), @@ -46,7 +47,8 @@ func TestApplyCmd(t *testing.T) { "-lock-timeout=200s", "-state=teststate", "-state-out=teststateout", - "-var-file=testvarfile", + "-var-file=foo.tfvars", + "-var-file=bar.tfvars", "-lock=false", "-parallelism=99", "-refresh=false", diff --git a/tfexec/destroy.go b/tfexec/destroy.go index 10895118..44529dbb 100644 --- a/tfexec/destroy.go +++ b/tfexec/destroy.go @@ -21,8 +21,8 @@ type destroyConfig struct { targets []string // Vars: each var must be supplied as a single string, e.g. 'foo=bar' - vars []string - varFile string + vars []string + varFiles []string } var defaultDestroyOptions = destroyConfig{ @@ -65,7 +65,7 @@ func (opt *StateOutOption) configureDestroy(conf *destroyConfig) { } func (opt *VarFileOption) configureDestroy(conf *destroyConfig) { - conf.varFile = opt.path + conf.varFiles = append(conf.varFiles, opt.path) } func (opt *LockOption) configureDestroy(conf *destroyConfig) { @@ -106,8 +106,8 @@ func (tf *Terraform) destroyCmd(ctx context.Context, opts ...DestroyOption) *exe if c.stateOut != "" { args = append(args, "-state-out="+c.stateOut) } - if c.varFile != "" { - args = append(args, "-var-file="+c.varFile) + for _, vf := range c.varFiles { + args = append(args, "-var-file="+vf) } // boolean and numerical opts: always pass diff --git a/tfexec/import.go b/tfexec/import.go index ab0cb3c8..6f4257c1 100644 --- a/tfexec/import.go +++ b/tfexec/import.go @@ -17,7 +17,7 @@ type importConfig struct { state string stateOut string vars []string - varFile string + varFiles []string } var defaultImportOptions = importConfig{ @@ -63,7 +63,7 @@ func (opt *VarOption) configureImport(conf *importConfig) { } func (opt *VarFileOption) configureImport(conf *importConfig) { - conf.varFile = opt.path + conf.varFiles = append(conf.varFiles, opt.path) } func (tf *Terraform) Import(ctx context.Context, address, id string, opts ...ImportOption) error { @@ -95,8 +95,8 @@ func (tf *Terraform) importCmd(ctx context.Context, address, id string, opts ... if c.stateOut != "" { args = append(args, "-state-out="+c.stateOut) } - if c.varFile != "" { - args = append(args, "-var-file="+c.varFile) + for _, vf := range c.varFiles { + args = append(args, "-var-file="+vf) } // boolean and numerical opts: always pass diff --git a/tfexec/plan.go b/tfexec/plan.go index 2aeb27c5..1de119af 100644 --- a/tfexec/plan.go +++ b/tfexec/plan.go @@ -18,7 +18,7 @@ type planConfig struct { state string targets []string vars []string - varFile string + varFiles []string } var defaultPlanOptions = planConfig{ @@ -38,7 +38,7 @@ func (opt *DirOption) configurePlan(conf *planConfig) { } func (opt *VarFileOption) configurePlan(conf *planConfig) { - conf.varFile = opt.path + conf.varFiles = append(conf.varFiles, opt.path) } func (opt *VarOption) configurePlan(conf *planConfig) { @@ -100,8 +100,8 @@ func (tf *Terraform) planCmd(ctx context.Context, opts ...PlanOption) *exec.Cmd if c.state != "" { args = append(args, "-state="+c.state) } - if c.varFile != "" { - args = append(args, "-var-file="+c.varFile) + for _, vf := range c.varFiles { + args = append(args, "-var-file="+vf) } // boolean and numerical opts: always pass diff --git a/tfexec/refresh.go b/tfexec/refresh.go index ae19dab3..5f8160c1 100644 --- a/tfexec/refresh.go +++ b/tfexec/refresh.go @@ -15,7 +15,7 @@ type refreshConfig struct { stateOut string targets []string vars []string - varFile string + varFiles []string } var defaultRefreshOptions = refreshConfig{ @@ -60,7 +60,7 @@ func (opt *VarOption) configureRefresh(conf *refreshConfig) { } func (opt *VarFileOption) configureRefresh(conf *refreshConfig) { - conf.varFile = opt.path + conf.varFiles = append(conf.varFiles, opt.path) } func (tf *Terraform) Refresh(ctx context.Context, opts ...RefreshCmdOption) error { @@ -89,8 +89,8 @@ func (tf *Terraform) refreshCmd(ctx context.Context, opts ...RefreshCmdOption) * if c.stateOut != "" { args = append(args, "-state-out="+c.stateOut) } - if c.varFile != "" { - args = append(args, "-var-file="+c.varFile) + for _, vf := range c.varFiles { + args = append(args, "-var-file="+vf) } // boolean and numerical opts: always pass