Prompt for input variables before context validate

Also adds a regression test using Mock UI. Fixes #3767.
This commit is contained in:
James Nugent 2015-11-10 13:31:15 -05:00
parent 4eea011b56
commit a49b162dd1
2 changed files with 30 additions and 3 deletions

View File

@ -68,14 +68,16 @@ func (c *PlanCommand) Run(args []string) int {
c.Ui.Error(err.Error()) c.Ui.Error(err.Error())
return 1 return 1
} }
if !validateContext(ctx, c.Ui) {
return 1
}
if err := ctx.Input(c.InputMode()); err != nil { if err := ctx.Input(c.InputMode()); err != nil {
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err)) c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
return 1 return 1
} }
if !validateContext(ctx, c.Ui) {
return 1
}
if refresh { if refresh {
c.Ui.Output("Refreshing Terraform state prior to plan...\n") c.Ui.Output("Refreshing Terraform state prior to plan...\n")
state, err := ctx.Refresh() state, err := ctx.Refresh()

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -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) { func TestPlan_varFile(t *testing.T) {
varFilePath := testTempFile(t) varFilePath := testTempFile(t)
if err := ioutil.WriteFile(varFilePath, []byte(planVarFile), 0644); err != nil { if err := ioutil.WriteFile(varFilePath, []byte(planVarFile), 0644); err != nil {