helper/schema: ResourceDiff ForceNew attribute correctness #17811
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A couple of bugs have been discovered in
ResourceDiff.ForceNew
:NewRemoved
is not preserved when a diff for a key is already present.This is because the second diff that happens after customization
performs a second
getChange
on not just state and config, but also onthe pre-existing diff. This results in
Exists == true
, meaning nil isnever returned as a new value.
ForceNew
was doing the work of adding the key to the list of changedkeys by doing a full
SetNew
on the existing value. This has a sideeffect of fetching zero values from what were otherwise undefined values
and creating diffs for these values where there should not have been
(example:
"" => "0"
).This update fixes these scenarios by:
NewRemoved
keys. This is included in the check on new values indiffChange
.ForceNew
(or parent keys of lists andsets that have been flagged as
ForceNew
) are now maintained in aseparate map.
UpdatedKeys
now returns the results of both of these maps,but otherwise these keys are ignored by
ResourceDiff
.newDiff
writer by ForceNew. This prevents the zero value problem, and makes for
a cleaner implementation where the provider has to "manually"
SetNew
toupdate the appropriate values in the writer. It also prevents
non-computed keys from winding up in the diff, which
ResourceDiff
normally blocks by design.
There are also a couple of tests for cases that should never come up
right now involving
Optional
/Computed
values andNewRemoved
, for whichexplanations are given in annotations of each test. These are here to
guard against future regressions.