From 95f43d823023ec3b6b07eefee5b92a8732385c19 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Oct 2014 08:43:00 -0700 Subject: [PATCH] command/apply: if with plan, don't ask for input [GH-346] --- command/apply.go | 8 +++++--- command/apply_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) 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) }