json-output: Add output type to JSON format#30945
Conversation
apparentlymart
left a comment
There was a problem hiding this comment.
LGTM! Exactly what I was imagining when we discussed this. 😀
| 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. | ||
|
|
There was a problem hiding this comment.
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"]
}
80e87d0 to
12c8f94
Compare
|
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
|
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. |
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
typefield in the usualctyJSON format, which allows reconstitution of the original value.For example, previously a
list(string)and aset(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"] }