jsonconfig: Additional details about input variables

The JSON object describing an input variable can now include two additional
properties:

- "type" provides a JSON representation of the variable's type constraint,
  if one is set. Omitted if either there is no constraint declared at all
  or if it's set to "any", which are equivalent and both mean that the
  type is completely unconstrained.

  This uses the standard cty representation of a type constraint, which
  matches how OpenTofu already describes types in the provider protocol,
  in state snapshots, and in saved plan files.
- "required" directly represents whether callers are required to provide
  a value for the variable. This is technically redundant since it is
  set to true unless "default" is also set, but this avoids the need for
  consuming software to reimplement this rule and potentially allows us to
  make this rule more complicated/subtle in future if needed.

For some reason the documentation about the JSON configuration
representation did not previously mention the "variables" property at all,
so this adds documentation for both the new properties and the pre-existing
properties.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins
2025-07-10 13:46:45 -07:00
parent 58cfe3d4d7
commit cbfeb0fdc8
8 changed files with 342 additions and 40 deletions

View File

@@ -79,7 +79,10 @@
}
],
"variables": {
"contents": {}
"contents": {
"required": true,
"type": "string"
}
}
},
"source": "./create"

View File

@@ -40,27 +40,110 @@
},
"variables": {
"list_empty_default": {
"default": []
"default": [],
"type": [
"list",
[
"object",
{
"optional_attribute": "string",
"optional_attribute_with_default": "string",
"required_attribute": "string"
},
[
"optional_attribute",
"optional_attribute_with_default"
]
]
]
},
"list_no_default": {
"required": true,
"type": [
"list",
[
"object",
{
"optional_attribute": "string",
"optional_attribute_with_default": "string",
"required_attribute": "string"
},
[
"optional_attribute",
"optional_attribute_with_default"
]
]
]
},
"list_no_default": {},
"nested_optional_object": {
"default": {
"nested_object": null
}
},
"type": [
"object",
{
"nested_object": [
"object",
{
"flag": "bool"
},
[
"flag"
]
]
},
[
"nested_object"
]
]
},
"nested_optional_object_with_default": {
"default": {
"nested_object": {
"flag": false
}
}
},
"type": [
"object",
{
"nested_object": [
"object",
{
"flag": "bool"
},
[
"flag"
]
]
},
[
"nested_object"
]
]
},
"nested_optional_object_with_embedded_default": {
"default": {
"nested_object": {
"flag": false
}
}
},
"type": [
"object",
{
"nested_object": [
"object",
{
"flag": "bool"
},
[
"flag"
]
]
},
[
"nested_object"
]
]
}
}
}