From 74873838e089b44d9b66378d265ca6c0dc6d2c99 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 24 May 2018 18:02:43 -0700 Subject: [PATCH] core: Fix TestContext2Input This test was previously not setting InputModeVarUnset, causing us to overwrite the "amis" map that _is_ already set. This worked before because we used to treat the empty result as an empty map and then merge it with the given value, but since we no longer do that merging behavior we were ending up with an empty map after input. Since the intent of this test is to see that the "foo" variable gets populated by input, here we add InputModeVarUnset which then matches how the input walk is triggered by the "real" codepath in the local backend. This also includes some updates to make the test fixture v0.12-idiomatic (applied after it was seen to work with the old fixture) and to properly handle the "diags" return value from the various context methods. --- terraform/context_input_test.go | 25 +++++++++------------- terraform/test-fixtures/input-vars/main.tf | 17 +++++++-------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 49a2ead7f..b1bb9c0d6 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -24,16 +24,11 @@ func TestContext2Input(t *testing.T) { }, ), Variables: InputValues{ - "foo": &InputValue{ - Value: cty.StringVal("us-west-2"), - SourceType: ValueFromCaller, - }, "amis": &InputValue{ - Value: cty.ListVal([]cty.Value{ - cty.MapVal(map[string]cty.Value{ - "us-east-1": cty.StringVal("override"), - }), + Value: cty.MapVal(map[string]cty.Value{ + "us-east-1": cty.StringVal("override"), }), + SourceType: ValueFromCaller, }, }, UIInput: input, @@ -43,17 +38,17 @@ func TestContext2Input(t *testing.T) { "var.foo": "us-east-1", } - if err := ctx.Input(InputModeStd); err != nil { - t.Fatalf("err: %s", err) + if diags := ctx.Input(InputModeStd | InputModeVarUnset); diags.HasErrors() { + t.Fatalf("input errors: %s", diags.Err()) } - if _, err := ctx.Plan(); err != nil { - t.Fatalf("err: %s", err) + if _, diags := ctx.Plan(); diags.HasErrors() { + t.Fatalf("plan errors: %s", diags.Err()) } - state, err := ctx.Apply() - if err != nil { - t.Fatalf("err: %s", err) + state, diags := ctx.Apply() + if diags.HasErrors() { + t.Fatalf("apply errors: %s", diags.Err()) } actual := strings.TrimSpace(state.String()) diff --git a/terraform/test-fixtures/input-vars/main.tf b/terraform/test-fixtures/input-vars/main.tf index 9c2d0b67d..905f5d75c 100644 --- a/terraform/test-fixtures/input-vars/main.tf +++ b/terraform/test-fixtures/input-vars/main.tf @@ -1,22 +1,21 @@ variable "amis" { - default = { - us-east-1 = "foo" - us-west-2 = "bar" - } + default = { + us-west-2 = "bar" + } } variable "bar" { - default = "baz" + default = "baz" } variable "foo" {} resource "aws_instance" "foo" { - num = "2" - bar = "${var.bar}" + num = "2" + bar = var.bar } resource "aws_instance" "bar" { - foo = "${var.foo}" - bar = "${lookup(var.amis, var.foo)}" + foo = var.foo + bar = var.amis[var.foo] }