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 adding show option to configure JSON decoding #426

Closed
bendbennett opened this issue Dec 8, 2023 · 0 comments · Fixed by #427
Closed

Consider adding show option to configure JSON decoding #426

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

Comments

@bendbennett
Copy link
Contributor

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.

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.

@bendbennett bendbennett added the enhancement New feature or request label Dec 8, 2023
bendbennett added a commit that referenced this issue Dec 14, 2023
bendbennett added a commit that referenced this issue Dec 14, 2023
@kmoe kmoe closed this as completed in #427 Dec 20, 2023
kmoe added a commit that referenced this issue Dec 20, 2023
* Adding ShowOption for JSON handling (#426)

* Temporarily pointing at terraform-json PR for dependent changes (#426)

* Ignoring fields that differ between TF versions (#426)

* Rename structs and func (#426)

* Removing redundant struct (#426)

* Update tfexec/options.go

Co-authored-by: kmoe <[email protected]>

* Updating to use renamed struct (#426)

* Bumping terraform-json to v0.19.0 (#426)

---------

Co-authored-by: kmoe <[email protected]>
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