helper/schema: arbitrary JSON attributes #3026
Closed
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.
Since provisioners implement directly their own configuration decoding, it's possible for them to have parameters that take arbitrary data structures, as we see in the
attributes
parameter of thechef
provisioner:For the OpsWorks support I've been working on in #2162 I'd like to be able to include a similar structure in a resource, since OpsWorks is essentially an interface to running Chef and thus I'd like it to follow the conventions of the Chef provisioner as much as possible.
Thus I'd like to propose a new schema type called
TypeJSON
, which represents any arbitrary JSON-friendly data structure as long as it is rooted in an object (amap[string]interface{}
). When writing a config file, the user may either assign a native HCL data structure like in the Chef example above, or they may assign a string containing a valid JSON-serialized data structure.Allowing both a native structure and a string has a few different advantages:
file()
interpolation function, in cases where the JSON structure is fixed and more convenient to maintain in a separate file.aws_iam_policy
, allowing them to be retroactively switched toTypeJSON
without breaking existing configurations.I've attached a prototype of this. It's has some known omissions, such as native structures containing nested computed interpolations, and there are no tests. However, my main goal here was to make this proposal and see what folks think about it before I try to push too much further in this direction.