Add json.Canonicalize to compute a canonical form of serialized JSON objects #344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR introduces the utility function
json.Canonicalize
to compute a canonical form of the serialized JSON objects. The canonical form is the minified JSON (white-space removed) with the object keys sorted.Based on this utility, we also introduce the
config.CanonicalizeJSONParameters
that returns aconfig.TerraformConfigurationInjector
for converting the specified list of top-level Terraform arguments with JSON values into their canonical forms. An example configuration is as follows:, where
policy
is a JSON security policy configuration. Assuming the following resource manifest:, the computed canonical form for the policy document is:
This PR also changes the function signature for the
config.ConfigurationInjector
function type to:, adding an
error
return value to be able to report errors while injecting Terraform configuration arguments. This is a breaking change and we assume the official providers are the only ones using thistype
.I have:
make reviewable
to ensure this PR is ready for review.backport release-x.y
labels to auto-backport this PR if necessary.How has this code been tested
Tested in the context of crossplane-contrib/provider-upjet-aws#1130 & crossplane-contrib/provider-upjet-aws#1150.