plans/objchange: when prior is null, computed attributes are unknown

This commit is contained in:
Martin Atkins 2018-08-27 18:51:15 -07:00
parent 7249a73f79
commit 3f8a973846
2 changed files with 6 additions and 5 deletions

View File

@ -26,9 +26,10 @@ import (
// block where _all_ attributes are computed.
func ProposedNewObject(schema *configschema.Block, prior, config cty.Value) cty.Value {
if prior.IsNull() {
// This is the easy case... no prior value to merge, so we can just
// return the config as-is.
return config
// In this case, we will treat the prior value as unknown so that
// any computed attributes not overridden in config will show as
// unknown values, rather than null values.
prior = cty.UnknownVal(schema.ImpliedType())
}
if config.IsNull() || !config.IsKnown() {
// This is a weird situation, but we'll allow it anyway to free

View File

@ -59,7 +59,7 @@ func TestProposedNewObject(t *testing.T) {
}),
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("hello"),
"bar": cty.NullVal(cty.String),
"bar": cty.UnknownVal(cty.String),
"baz": cty.ObjectVal(map[string]cty.Value{
"boz": cty.StringVal("world"),
}),
@ -432,7 +432,7 @@ func TestProposedNewObject(t *testing.T) {
}),
cty.ObjectVal(map[string]cty.Value{
"bar": cty.StringVal("bosh"),
"baz": cty.NullVal(cty.String),
"baz": cty.UnknownVal(cty.String),
}),
}),
}),