Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple VarFile options #61

Merged
merged 1 commit into from
Aug 29, 2020
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: 5 additions & 5 deletions tfexec/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tfexec/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tfexec/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tfexec/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type importConfig struct {
state string
stateOut string
vars []string
varFile string
varFiles []string
}

var defaultImportOptions = importConfig{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tfexec/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type planConfig struct {
state string
targets []string
vars []string
varFile string
varFiles []string
}

var defaultPlanOptions = planConfig{
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tfexec/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type refreshConfig struct {
stateOut string
targets []string
vars []string
varFile string
varFiles []string
}

var defaultRefreshOptions = refreshConfig{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down