From 3f8a97384636479b7aafdb4ee4eefa946caee08a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 27 Aug 2018 18:51:15 -0700 Subject: [PATCH] plans/objchange: when prior is null, computed attributes are unknown --- plans/objchange/objchange.go | 7 ++++--- plans/objchange/objchange_test.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plans/objchange/objchange.go b/plans/objchange/objchange.go index 8d28749b4e..5870dbf33b 100644 --- a/plans/objchange/objchange.go +++ b/plans/objchange/objchange.go @@ -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 diff --git a/plans/objchange/objchange_test.go b/plans/objchange/objchange_test.go index ccab0d4b74..e7b39430b3 100644 --- a/plans/objchange/objchange_test.go +++ b/plans/objchange/objchange_test.go @@ -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), }), }), }),