diff --git a/command/apply.go b/command/apply.go index 9732882f4..4216bcac0 100644 --- a/command/apply.go +++ b/command/apply.go @@ -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) { diff --git a/command/apply_test.go b/command/apply_test.go index 4423b3b2e..e5c5a6b08 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -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) }