Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command/meta: always ask for unset variable input #9794

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions command/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,47 @@ func TestApply_input(t *testing.T) {
}
}

// When only a partial set of the variables are set, Terraform
// should still ask for the unset ones by default (with -input=true)
func TestApply_inputPartial(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("one\ntwo\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,
"-var", "foo=foovalue",
testFixturePath("apply-input-partial"),
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}

expected := strings.TrimSpace(`
<no state>
Outputs:

bar = one
foo = foovalue
`)
testStateOutput(t, statePath, expected)
}

func TestApply_noArgs(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,8 @@ func (m *Meta) InputMode() terraform.InputMode {

var mode terraform.InputMode
mode |= terraform.InputModeProvider
if len(m.variables) == 0 {
mode |= terraform.InputModeVar
mode |= terraform.InputModeVarUnset
}
mode |= terraform.InputModeVar
mode |= terraform.InputModeVarUnset

return mode
}
Expand Down
6 changes: 5 additions & 1 deletion command/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ func TestMetaInputMode_vars(t *testing.T) {
t.Fatalf("err: %s", err)
}

if m.InputMode()&terraform.InputModeVar != 0 {
if m.InputMode()&terraform.InputModeVar == 0 {
t.Fatalf("bad: %#v", m.InputMode())
}

if m.InputMode()&terraform.InputModeVarUnset == 0 {
t.Fatalf("bad: %#v", m.InputMode())
}
}
Expand Down
5 changes: 5 additions & 0 deletions command/test-fixtures/apply-input-partial/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "foo" {}
variable "bar" {}

output "foo" { value = "${var.foo}" }
output "bar" { value = "${var.bar}" }
3 changes: 2 additions & 1 deletion terraform/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
// InputModeVar asks for all variables
InputModeVar InputMode = 1 << iota

// InputModeVarUnset asks for variables which are not set yet
// InputModeVarUnset asks for variables which are not set yet.
// InputModeVar must be set for this to have an effect.
InputModeVarUnset

// InputModeProvider asks for provider variables
Expand Down