- Notifications
You must be signed in to change notification settings - Fork28
Description
Background
Theterraform-exec Go module explicitly sets theuseJSONNumber field to true on thetfjson.State struct by callingUseJSONNumber(true) within theShow() method prior to the implicit call toUnmarshalJSON() ontfjson.State. As a consequence, numerical values that are returned when the state is obtained by calling theShow() method on terraform-exec are of typejson.Number.
Thetfjson.Plan struct does not currently surface a way to modify the handling of numerical values when decoding JSON, as there is nouseJSONNumber field on thetfjson.Plan struct, and no correspondingUseJSONNumber() method for setting such a field. As a consequence, numerical values that are obtained when calling methods such asShowPlanFile() are of typefloat64.
Use-Case
ThisRFC proposes extending plan check functionality withinterraform-plugin-testing to add plan checks for resource attributes and outputs values with a known value and type. Prototyping these known type and value plan checks revealed the limitations of numerical values being of typefloat64 intfjson.Plan in terms of being able to check their values.
Proposal
Thetfjson.Plan struct could be modified to add auseJSONNumber field, and to expose aUseJSONNumber() method on the struct. TheUnmarshalJSON() method could then be altered to perform JSON decoding in the same way astfjson.State, by checking the value ofuseJSONNumber to determine the decoding strategy for numerical values.
Additional Considerations
If this proposal proceeds, then terraform-exec will also require amending, likely by either adding aShowOption for configuring handling of numerical values, or perhaps, adding an additional function to allow obtaining the plan with JSON number used for numerical values.