-
Notifications
You must be signed in to change notification settings - Fork 2
Description
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 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.
Activity
skyzyx commentedon Jan 23, 2025
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:
jsonencode
.corefunc::deep_merge()
function of some kind (using darccio/mergo). Respond with JSON.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.
skyzyx commentedon Jan 23, 2025
Note to self: https://pkg.go.dev/github.com/santhosh-tekuri/jsonschema/v6#example-package-FromStrings
feat: adds the runtime_overrides variable + tests (#44)