terraform/helper
Chris Marchesi d7048cb640
helper/schema: ResourceDiff ForceNew attribute correctness
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 on
the pre-existing diff. This results in Exists == true, meaning nil is
never returned as a new value.
* ForceNew was doing the work of adding the key to the list of changed
keys by doing a full SetNew on the existing value. This has a side
effect 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:

* Adding a new private function to check the existing diff for
NewRemoved keys. This is included in the check on new values in
diffChange.
* Keys that have been flagged as ForceNew (or parent keys of lists and
sets that have been flagged as ForceNew) are now maintained in a
separate map. UpdatedKeys now returns the results of both of these maps,
but otherwise these keys are ignored by ResourceDiff.
* Pursuant the above, values are no longer pushed into the newDiff
writer by ForceNew. This prevents the zero value problem, and makes for
a cleaner implementation where the provider has to "manually" SetNew to
update 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 and NewRemoved, for which
explanations are given in annotations of each test. These are here to
guard against future regressions.
2018-04-08 07:50:41 -07:00
..
acctest Fix swallowed err in acctest package 2017-07-19 16:24:41 -07:00
config
copy
customdiff helper/customdiff: Helper functions for CustomizeDiff 2017-12-18 10:38:20 -08:00
didyoumean helper/didyoumean: helper library for "Did you mean ...? suggestions 2017-10-16 17:50:57 -07:00
diff
encryption
experiment
hashcode hashcode: "Strings" function for hashing slices of strings 2017-10-20 14:54:23 -07:00
hilmapstructure
logging helper: Allow logs isolation per acceptance test 2017-10-14 16:39:11 +03:00
mutexkv
pathorcontents
resource Fixing small typo in resource/wait.go 2018-03-14 17:33:03 +01:00
schema helper/schema: ResourceDiff ForceNew attribute correctness 2018-04-08 07:50:41 -07:00
shadow Make sure shadow.closeWalker doesn't copy Mutexes 2017-07-07 11:20:54 -04:00
signalwrapper
slowmessage
structure helper/structure: More cases for NormalizeJsonString tests 2018-01-17 15:53:38 -08:00
validation helper/validation: IP address and IP address range validation helpers 2018-03-29 09:41:59 -07:00
variables command/init: backend-config accepts key=value pairs 2017-03-16 23:27:05 -07:00
wrappedreadline
wrappedstreams
README.md

README.md

Helper Libraries

This folder contains helper libraries for Terraform plugins. A running joke is that this is "Terraform standard library" for plugins. The goal of the packages in this directory are to provide high-level helpers to make it easier to implement the various aspects of writing a plugin for Terraform.