diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a7fcbfa3..9cd0d66d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ BUG FIXES: * core: JSON TF configurations can configure provisioners. [GH-807] * command/apply: Won't try to initialize modules in some cases when no arguments are given. [GH-780] + * command/apply: Fix regression where user variables weren't asked [GH-736] * provider/aws: ELB subnet change doesn't force new resource. [GH-804] PLUGIN CHANGES: diff --git a/command/apply.go b/command/apply.go index 153ae3a63..a568b0431 100644 --- a/command/apply.go +++ b/command/apply.go @@ -120,15 +120,15 @@ func (c *ApplyCommand) Run(args []string) int { return 1 } } - if !validateContext(ctx, c.Ui) { - return 1 - } if !planned { if err := ctx.Input(c.InputMode()); err != nil { c.Ui.Error(fmt.Sprintf("Error configuring: %s", err)) return 1 } } + if !validateContext(ctx, c.Ui) { + return 1 + } // Plan if we haven't already if !planned { diff --git a/command/apply_test.go b/command/apply_test.go index bac67d7ba..6c8643b87 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -268,6 +268,39 @@ func TestApply_init(t *testing.T) { } } +func TestApply_input(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 = bytes.NewBufferString("foo\n") + defaultInputWriter = new(bytes.Buffer) + + statePath := testTempFile(t) + + p := testProvider() + ui := new(cli.MockUi) + c := &ApplyCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + + args := []string{ + "-state", statePath, + testFixturePath("apply-input"), + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + if !p.InputCalled { + t.Fatal("input should be called") + } +} + func TestApply_noArgs(t *testing.T) { cwd, err := os.Getwd() if err != nil { diff --git a/command/test-fixtures/apply-input/main.tf b/command/test-fixtures/apply-input/main.tf new file mode 100644 index 000000000..55072f712 --- /dev/null +++ b/command/test-fixtures/apply-input/main.tf @@ -0,0 +1,3 @@ +variable "foo" {} + +resource "test_instance" "foo" {}