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.
This commit is contained in:
parent
1b55f09891
commit
74873838e0
|
@ -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{
|
||||
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())
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
variable "amis" {
|
||||
default = {
|
||||
us-east-1 = "foo"
|
||||
us-west-2 = "bar"
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +12,10 @@ variable "foo" {}
|
|||
|
||||
resource "aws_instance" "foo" {
|
||||
num = "2"
|
||||
bar = "${var.bar}"
|
||||
bar = var.bar
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${var.foo}"
|
||||
bar = "${lookup(var.amis, var.foo)}"
|
||||
foo = var.foo
|
||||
bar = var.amis[var.foo]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue