Add failing test for missing computed map entries

The map output from the module "mod" loses the computed value from the
template when we validate. If the "extra" field is removed from the map,
the validation fails earlier with map "does not have any elements so
cannot determine type".

Apply will work, because the computed value will exist in the map.
This commit is contained in:
James Bardin 2016-10-26 16:05:50 -04:00 committed by Mitchell Hashimoto
parent 064691b03c
commit f7d6fb368a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 45 additions and 0 deletions

View File

@ -821,3 +821,29 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
t.Fatal("err:", e)
}
}
// Computed values are lost when a map is output from a module
func TestContext2Validate_interpolateMap(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "issue-9549")
p := testProvider("null")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"template": testProviderFuncFixed(p),
},
UIInput: input,
})
w, e := ctx.Validate()
if w != nil {
t.Log("warnings:", w)
}
if e != nil {
t.Fatal("err:", e)
}
}

View File

@ -0,0 +1,7 @@
module "mod" {
source = "./mod"
}
resource "template_file" "root_template" {
template = "ext: ${module.mod.base_config["base_template"]}"
}

View File

@ -0,0 +1,12 @@
resource "template_file" "example" {
template = "template text"
}
output "base_config" {
value = {
base_template = "${template_file.example.rendered}"
# without this we fail with no entries
extra = "value"
}
}