You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My team and I have run into an issue a number of times with what I'm calling the "Optional Type Defaults Problem" (bad name). Lots of info in the OpenTofu Slack. The quick summary: when merging objects with optional fields, there can be null values that unintentionally override desired defaults. This leads to unexpected / undesired behavior in complex module configurations.
The end result of this issue is that we can't use the TF type system to do what we want and instead we're going to specify any as our type for complex objects in certain cases and then we'll use a JSON schema to validate the given variable value at runtime. To do this today, we're thinking about using the jsonschema_validator data source from the jsonschema providera. However that is an old, seemingly unpopular provider and the validation is not implemented as a function.
I would love to see a str_jsonschema_validate function in this provider. If there is interest, I can try to put up a PR to add this.
The text was updated successfully, but these errors were encountered:
I've been job hunting recently, so I've not been working on this as quickly as I'd like, but I was already looking into implementing this before I got laid off.
The native type system is complex. So if there's merging involved, I've been experimenting with:
Encoding a native type (or types) as JSON via jsonencode.
Passing that to a corefunc::deep_merge() function of some kind (using darccio/mergo). Respond with JSON.
Decode back to native types via jsondecode.
I like the idea of validating inputs using JSON Schema (using something like santhosh-tekuri/jsonschema, which supports a broad set of dialects).
Perhaps a JSON validation function could slide between steps 2 and 3, with the option to WARN or ERROR on failure. I was trying to do something like this at a module level back in the Terraform 0.14 days when "optionals" were introduced as an experiment. I think I have some good test cases for such a feature.
What functionality would you like to see?
My team and I have run into an issue a number of times with what I'm calling the "Optional Type Defaults Problem" (bad name). Lots of info in the OpenTofu Slack. The quick summary: when merging objects with optional fields, there can be null values that unintentionally override desired defaults. This leads to unexpected / undesired behavior in complex module configurations.
The end result of this issue is that we can't use the TF type system to do what we want and instead we're going to specify
any
as our type for complex objects in certain cases and then we'll use a JSON schema to validate the given variable value at runtime. To do this today, we're thinking about using thejsonschema_validator
data source from the jsonschema providera. However that is an old, seemingly unpopular provider and the validation is not implemented as a function.I would love to see a
str_jsonschema_validate
function in this provider. If there is interest, I can try to put up a PR to add this.The text was updated successfully, but these errors were encountered: