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 {
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
return 1
if !planned {
if err := ctx.Input(); err != nil {
c.Ui.Error(fmt.Sprintf("Error configuring: %s", err))
return 1
}
}
}
if !validateContext(ctx, c.Ui) {

View File

@ -1,6 +1,7 @@
package command
import (
"bytes"
"fmt"
"io/ioutil"
"net"
@ -314,6 +315,14 @@ func TestApply_noArgs(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{
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())
}
if p.InputCalled {
t.Fatalf("input should not be called for plans")
}
if _, err := os.Stat(statePath); err != nil {
t.Fatalf("err: %s", err)
}