command/apply: if with plan, don't ask for input [GH-346]

This commit is contained in:
Mitchell Hashimoto 2014-10-01 08:43:00 -07:00
parent 817f0d9f30
commit 95f43d8230
2 changed files with 18 additions and 3 deletions

View File

@ -132,9 +132,11 @@ func (c *ApplyCommand) Run(args []string) int {
} }
} }
if err := ctx.Input(); err != nil { if !planned {
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err)) if err := ctx.Input(); err != nil {
return 1 c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
return 1
}
} }
} }
if !validateContext(ctx, c.Ui) { if !validateContext(ctx, c.Ui) {

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net" "net"
@ -314,6 +315,14 @@ func TestApply_noArgs(t *testing.T) {
} }
func TestApply_plan(t *testing.T) { func TestApply_plan(t *testing.T) {
// Disable test mode so input would be asked
test = false
defer func() { test = true }()
// Set some default reader/writers for the inputs
defaultInputReader = new(bytes.Buffer)
defaultInputWriter = new(bytes.Buffer)
planPath := testPlanFile(t, &terraform.Plan{ planPath := testPlanFile(t, &terraform.Plan{
Module: testModule(t, "apply"), Module: testModule(t, "apply"),
}) })
@ -336,6 +345,10 @@ func TestApply_plan(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if p.InputCalled {
t.Fatalf("input should not be called for plans")
}
if _, err := os.Stat(statePath); err != nil { if _, err := os.Stat(statePath); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }