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:
parent
064691b03c
commit
f7d6fb368a
|
@ -821,3 +821,29 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
|
||||||
t.Fatal("err:", e)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
module "mod" {
|
||||||
|
source = "./mod"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "template_file" "root_template" {
|
||||||
|
template = "ext: ${module.mod.base_config["base_template"]}"
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue