You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go's JSON decoder, by default, uses a lossy conversion of JSON integers
to float64s. For sufficiently large integers, this yields a loss of
precision, and that causes problems with diffs and plans not matching.
See hashicorp/terraform-plugin-sdk#655 for more details.
This PR proposes a solution: keeping the lossless json.Number
representation of integers in state files. This will ensure that no
precision is lost, but it comes at a cost. json.Number is a string type,
not a float64 type. That means that existing state upgraders that
(correctly) cast a value to float64 will break, as the value will now be
surfaced to them as a json.Number, which cannot be cast to a float64.
To handle this, the schema.Resource type gains a `UseJSONNumber`
property. When set to new, users are opted into the new json.Number
values. When left false, the default, users get the existing float64
behavior.
If a resource with state upgraders wants to use the new json.Number
behavior, it must update all the state upgraders for that resource to
use json.Number instead of float64 or users with old state files will
panic during upgrades.
Note: the backwards compatibility properties of this commit are unknown
at this time, and there may be a way for us to avoid using
schema.Resource.UseJSONNumber, instead preserving the choice until we
get to the point where TypeInt casts the number to an int. Further
investigation needed.
0 commit comments