Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing configuration of tfjson.Plan to use JSON number #111

Closed
bendbennett opened this issue Dec 6, 2023 · 0 comments · Fixed by #113
Closed

Consider allowing configuration of tfjson.Plan to use JSON number #111

bendbennett opened this issue Dec 6, 2023 · 0 comments · Fixed by #113
Labels
enhancement New feature or request

Comments

@bendbennett
Copy link
Contributor

bendbennett commented Dec 6, 2023

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 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.

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 a UseJSONNumber() method on the struct. The UnmarshalJSON() method could then be altered to perform JSON decoding in the same way as tfjson.State, by checking the value of useJSONNumber 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant