-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make detailed type constraints easier to discover from the input variables docs #35570
Comments
Hi @stonefield, I don't think I understand the proposal here, is your goal here is to have defaults for
Which would leave Thanks! |
Thanks @jbardin, This was a epiphany for me. It is not apparent when reading the documentation for variables here: It does not give examples that leads to this understanding. However, doing some more research, I found this link: Maybe an update of the documentation will help others revealing this solution. Feel free to update the documentation and/or close the issue if you wish. |
Terraform Version
Use Cases
I try to define an input variable defined as an object, where I would like to set optional attributes to a default value.
Ideal declaration:
In the case above I would like deletion_protection to default to true. Terraform reports:
This default value is not compatible with the variable's type constraint: attributes "name" and "user_name" are required.
Attempted Solutions
Workaround Removing defaults
allow terraform to run, but now there is no documentation describing the default since it is handled elsewhere.
Attempt to workaround 1 - unsuccessful
assign the default by using a local variable.
Now, if specifying only the required attributes, the optional key
deletion_protection
is stillnull
, becausedeletion_protection
is assigned by terraform asbool(null)
.Work around 2 - successful
Using a loop to assign the default:
Work around 3 - successful
Trying to make the code more generic and efficient when default values
Workaround Assigning required attributes default value of null
In the scenario above the mandatory keys are assigned to null and validation has to be done in order to fulfill the requirement of mandatory keys. However. The issue with the the default values are still problem as they are assigned null by terraform as long as the object is specified.
Proposal
My initial use case is the optimum solution. Explanation:
If type is declared as object and it contains optional attributes
default
to only contain optional attributes.During processing of the variable:
My rationale:
If you feel that support for more complex structures hinders implementing of the solution, then my advise would be to only support a reduced number of levels, such as minimum one
References
No response
The text was updated successfully, but these errors were encountered: