From 50023e9a60aac7324f9e28fc1aa79a2415a4ca78 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 29 Mar 2017 16:45:25 -0400 Subject: [PATCH] honor `input=false` in state migration return an error when confirming a copy if -input=false --- command/init_test.go | 26 ++++++++++++++++++++++++++ command/meta.go | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/command/init_test.go b/command/init_test.go index a0a8c32a0..eea5797c1 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -508,6 +508,32 @@ func TestInit_backendReinitConfigToExtra(t *testing.T) { } } +// make sure inputFalse stops execution on migrate +func TestInit_inputFalse(t *testing.T) { + td := tempDir(t) + copy.CopyDir(testFixturePath("init-backend"), td) + defer os.RemoveAll(td) + defer testChdir(t, td)() + + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{"-input=false", "-backend-config=path=foo"} + if code := c.Run([]string{"-input=false"}); code != 0 { + t.Fatalf("bad: \n%s", ui.ErrorWriter) + } + + args = []string{"-input=false", "-backend-config=path=bar"} + if code := c.Run(args); code == 0 { + t.Fatal("init should have failed", ui.OutputWriter) + } +} + /* func TestInit_remoteState(t *testing.T) { tmp, cwd := testCwd(t) diff --git a/command/meta.go b/command/meta.go index 0dd4c7884..daf949a29 100644 --- a/command/meta.go +++ b/command/meta.go @@ -3,6 +3,7 @@ package command import ( "bufio" "bytes" + "errors" "flag" "fmt" "io" @@ -341,6 +342,9 @@ func (m *Meta) uiHook() *UiHook { // confirm asks a yes/no confirmation. func (m *Meta) confirm(opts *terraform.InputOpts) (bool, error) { + if !m.input { + return false, errors.New("input disabled") + } for { v, err := m.UIInput().Input(opts) if err != nil {