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 type json.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 corresponding UseJSONNumber() method for setting such a field. As a consequence, numerical values that are obtained when calling methods such as ShowPlanFile() are of type float64.
A PR has been opened on terraform-plugin-json which adds a useJSONNumber field to the tfjson.Plan struct, adds a corresponding UseJSONNumber() method for setting such a field, and correspondingly modifies the UnmarshalJSON() method on tfjson.Plan to take the value of useJSONNumber into account.
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
Implementations of ShowOption could be extended to include a JSONOption which could contain configuration used to determine how JSON decoding should be handled. Adding such an option would be contingent upon the changes included in the PR on terraform-plugin-json. This would provide a mechanism for callers of, for instance, ShowPlanFile, to be able to obtain numerical values in tfjson.Plan as type json.Number.
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
.A PR has been opened on terraform-plugin-json which adds a
useJSONNumber
field to the tfjson.Plan struct, adds a correspondingUseJSONNumber()
method for setting such a field, and correspondingly modifies theUnmarshalJSON()
method on tfjson.Plan to take the value ofuseJSONNumber
into account.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
Implementations of ShowOption could be extended to include a
JSONOption
which could contain configuration used to determine how JSON decoding should be handled. Adding such an option would be contingent upon the changes included in the PR on terraform-plugin-json. This would provide a mechanism for callers of, for instance, ShowPlanFile, to be able to obtain numerical values in tfjson.Plan as typejson.Number
.