Skip to content

Commit

Permalink
Prompt for input variables before context validate
Browse files Browse the repository at this point in the history
Also adds a regression test using Mock UI. Fixes #3767.
  • Loading branch information
jen20 committed Nov 10, 2015
1 parent 4eea011 commit a49b162
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ func (c *PlanCommand) Run(args []string) int {
c.Ui.Error(err.Error())
return 1
}
if !validateContext(ctx, c.Ui) {
return 1
}

if err := ctx.Input(c.InputMode()); err != nil {
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
return 1
}

if !validateContext(ctx, c.Ui) {
return 1
}

if refresh {
c.Ui.Output("Refreshing Terraform state prior to plan...\n")
state, err := ctx.Refresh()
Expand Down
25 changes: 25 additions & 0 deletions command/plan_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -330,6 +331,30 @@ func TestPlan_vars(t *testing.T) {
}
}

func TestPlan_varsUnset(t *testing.T) {
// Disable test mode so input would be asked
test = false
defer func() { test = true }()

defaultInputReader = bytes.NewBufferString("bar\n")

p := testProvider()
ui := new(cli.MockUi)
c := &PlanCommand{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}

args := []string{
testFixturePath("plan-vars"),
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
}

func TestPlan_varFile(t *testing.T) {
varFilePath := testTempFile(t)
if err := ioutil.WriteFile(varFilePath, []byte(planVarFile), 0644); err != nil {
Expand Down

0 comments on commit a49b162

Please sign in to comment.