From 6a4f7b0dce4459a75ebdfc2bc9fe406dd340a1dd Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Sat, 27 May 2017 16:46:42 -0700 Subject: [PATCH] helper/schema: Don't ignore diffs for certain NewComputed keys In diffString, removed values are marked if the old value is non-nil and the new value is nil, regardless of if the new value is marked as a computed value. With the new diff override behaviour, this can lead to issues where a nil attribute may get inserted into the diff if the new value has been marked as computed (as the value will be marked as missing, but computed). This propagates into finalizeDiff in some respects because even if NewComputed is manually set in the diff that gets passed in, it is ignored, and the schema becomes the only source of truth. Since our new diff behaviour is mainly designed to be supported on computed keys only, it stands to reason that we there will be a time where we want to set a diff as NewComputed on a key, and see that change in the diff. These two small changes makes that happen. No regressions in tests have been observed via this change, so it seems safe and non-invasive. --- helper/schema/schema.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 67bbe112a..362e7e6b1 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -333,7 +333,7 @@ func (s *Schema) finalizeDiff( return d } - if s.Computed { + if s.Computed && !d.NewComputed { if d.Old != "" && d.New == "" { // This is a computed value with an old value set already, // just let it go. @@ -1107,7 +1107,7 @@ func (m schemaMap) diffString( } removed := false - if o != nil && n == nil { + if o != nil && n == nil && !computed { removed = true } if removed && schema.Computed {