Consider allowing configuration of tfjson.Plan
to use JSON number
#111
Labels
enhancement
New feature or request
tfjson.Plan
to use JSON number
#111
Background
The terraform-exec Go module explicitly sets the
useJSONNumber
field to true on the tfjson.State struct by calling UseJSONNumber(true) within the Show() method prior to the implicit call to UnmarshalJSON() on tfjson.State. As a consequence, numerical values that are returned when the state is obtained by calling the Show() method on terraform-exec are of typejson.Number
.The tfjson.Plan struct does not currently surface a way to modify the handling of numerical values when decoding JSON, as there is no
useJSONNumber
field on the tfjson.Plan struct, and no correspondingUseJSONNumber()
method for setting such a field. As a consequence, numerical values that are obtained when calling methods such as ShowPlanFile() are of typefloat64
.Use-Case
This RFC proposes extending plan check functionality within terraform-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 type
float64
in tfjson.Plan in terms of being able to check their values.Proposal
The tfjson.Plan struct could be modified to add a
useJSONNumber
field, and to expose aUseJSONNumber()
method on the struct. TheUnmarshalJSON()
method could then be altered to perform JSON decoding in the same way as tfjson.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 a
ShowOption
for configuring handling of numerical values, or perhaps, adding an additional function to allow obtaining the plan with JSON number used for numerical values.The text was updated successfully, but these errors were encountered: