3fa11e456b
There are situations where one may need to write to a set, list, or map more than once per single TF operation (apply/refresh/etc). In these cases, further writes using Set (example: d.Set("some_set", newSet)) currently create unstable results in the set writer (the name of the writer layer that holds the data set by these calls) because old keys are not being cleared out first. This bug is most visible when using sets. Example: First write to set writes elements that have been hashed at 10 and 20, and the second write writes elements that have been hashed at 30 and 40. While the set length has been correctly set at 2, since a set is basically a map (as is the entire map writer) and map results are non-deterministic, reads to this set will now deliver unstable results in a random but predictable fashion as the map results are delivered to the caller non-deterministic - sometimes you may correctly get 30 and 40, but sometimes you may get 10 and 20, or even 10 and 30, etc. This problem propagates to state which is even more damaging as unstable results are set to state where they become part of the permanent data set going forward. The problem also applies to lists and maps. This is probably more of an issue with maps as a map can contain any key/value combination and hence there is no predictable pattern where keys would be overwritten with default or zero values. This is contrary to complex lists, which has this problem as well, but since lists are deterministic and the length of a list properly gets updated during the overwrite, the problem is masked by the fact that a read will only read to the boundary of the list, skipping any bad data that may still be available due past the list boundary. This update clears the child contents of any set, list, or map before beginning a new write to address this issue. Tests are included for all three data types. |
||
---|---|---|
.. | ||
README.md | ||
backend.go | ||
backend_test.go | ||
core_schema.go | ||
core_schema_test.go | ||
data_source_resource_shim.go | ||
equal.go | ||
field_reader.go | ||
field_reader_config.go | ||
field_reader_config_test.go | ||
field_reader_diff.go | ||
field_reader_diff_test.go | ||
field_reader_map.go | ||
field_reader_map_test.go | ||
field_reader_multi.go | ||
field_reader_multi_test.go | ||
field_reader_test.go | ||
field_writer.go | ||
field_writer_map.go | ||
field_writer_map_test.go | ||
getsource_string.go | ||
provider.go | ||
provider_test.go | ||
provisioner.go | ||
provisioner_test.go | ||
resource.go | ||
resource_data.go | ||
resource_data_get_source.go | ||
resource_data_test.go | ||
resource_diff.go | ||
resource_diff_test.go | ||
resource_importer.go | ||
resource_test.go | ||
resource_timeout.go | ||
resource_timeout_test.go | ||
schema.go | ||
schema_test.go | ||
serialize.go | ||
serialize_test.go | ||
set.go | ||
set_test.go | ||
testing.go | ||
valuetype.go | ||
valuetype_string.go |
README.md
Terraform Helper Lib: schema
The schema
package provides a high-level interface for writing resource
providers for Terraform.
If you're writing a resource provider, we recommend you use this package.
The interface exposed by this package is much friendlier than trying to write to the Terraform API directly. The core Terraform API is low-level and built for maximum flexibility and control, whereas this library is built as a framework around that to more easily write common providers.