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

json-output: Add output type to JSON format #30945

Merged
merged 1 commit into from Apr 27, 2022

Conversation

alisdair
Copy link
Member

Previously the supported JSON plan and state formats included only serialized output values, which was a lossy serialization of the Terraform type system. This commit adds a type field in the usual cty JSON format, which allows reconstitution of the original value.

For example, previously a list(string) and a set(string) containing the same values were indistinguishable. This change serializes these as follows:

{
  "value": ["a","b","c"],
  "type": ["list","string"]
}

and:

{
  "value": ["a","b","c"],
  "type": ["set","string"]
}

@alisdair alisdair added json-output 1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged labels Apr 27, 2022
@alisdair alisdair requested a review from a team April 27, 2022 17:21
@alisdair alisdair self-assigned this Apr 27, 2022
Copy link
Member

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Exactly what I was imagining when we discussed this. 😀

Comment on lines 311 to 312
Output values include a `"type"` field, which is a [serialization of the value's type](https://pkg.go.dev/github.com/zclconf/go-cty/cty#Type.MarshalJSON). For primitive types this is a string value, such as `"number"` or `"bool"`. Complex types are represented as a nested JSON array, such as `["map","string"]` or `["object",{"a":"number"]]`. This can be used to reconstruct the output value with the correct type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should aim to inline the information about this into this document rather than referring to the external dependency that happens to implement it today, but this does seem like a reasonable compromise to allow us to get moving on this relatively quickly and improve the docs separately later.

Previously the supported JSON plan and state formats included only
serialized output values, which was a lossy serialization of the
Terraform type system. This commit adds a type field in the usual cty
JSON format, which allows reconstitution of the original value.

For example, previously a list(string) and a set(string) containing the
same values were indistinguishable. This change serializes these as
follows:

{
  "value": ["a","b","c"],
  "type": ["list","string"]
}

and:

{
  "value": ["a","b","c"],
  "type": ["set","string"]
}
@alisdair alisdair force-pushed the alisdair/jsonstate-output-type branch from 80e87d0 to 12c8f94 Compare April 27, 2022 17:30
@alisdair alisdair merged commit b02867b into main Apr 27, 2022
@alisdair alisdair deleted the alisdair/jsonstate-output-type branch April 27, 2022 17:36
@github-actions
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged json-output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants