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.
This commit is contained in:
Chris Marchesi 2017-05-27 16:46:42 -07:00 committed by Martin Atkins
parent 64cc4084d2
commit 6a4f7b0dce
1 changed files with 2 additions and 2 deletions

View File

@ -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 {