Hi all ,
I’m the Product Manager for Terraform Core, and we’re excited to share our v1.3 alpha , which includes the ability to mark object type attributes as optional, as well as set default values (draft documentation here). With the delivery of this much requested language feature, we will conclude the existing experiment with an improved design. Below you can find some background information about this language feature, or you can read on to see how to participate in the alpha and provide feedback.
To mark an attribute as optional, use the additional optional(...)
modifier around its type declaration:
variable "with_optional_attribute" {
type = object({
a = string # a required attribute
b = optional(string) # an optional attribute
c = optional(number, 127) # an optional attribute with default value
})
}
Background
As many of you know, in Terraform v0.14 we introduced experimental support for an optional modifier for object attributes, which replaced missing attributes with null
. Your helpful feedback validated the idea itself, but highlighted a need for specifying defaults for optional attributes. In Terraform v0.15, we added an experimental defaults() function, which allows filling null
attribute values with defaults. This resulted in extensive community feedback, and many of you found the defaults function confusing when used with complex structures, or inappropriate for your needs.
We know this experiment has been out in the wild for some time, and we’re incredibly grateful for your patience and feedback on the necessity of this language feature. With that, we’d love for you to try the new syntax available in the v1.3 alpha, and provide any and all feedback.
How to provide feedback
This feature is currently experimental, with the goal of stabilizing a finished feature in the v1.3.0 release. That being said, your feedback and bug reports are vital to us confidently releasing this feature as non-experimental during this release cycle.
Experience reports
Please try out this feature in the alpha release, and let us know what you think. For example:
- Does this new design solve your problems?
- Do you have any feedback on the semantics?
- Is the documentation sufficiently clear?
Bug reports
- For any bugs, please open issues in our repository here.
- For any edge cases that are not solved by this design, you can also open an issue in our repo.
General feedback
For general feedback, please comment directly on this post. If you’d prefer to have a private discussion, you can email me directly (kalpers@hashicorp.com). However, public posts are most helpful for our team to review.
Note
Because this feature is currently experimental, it requires an explicit opt-in on a per-module basis. To use it, write a terraform
block with the experiments
argument set as follows:
terraform {
experiments = [module_variable_optional_attrs]
}
Until the experiment is concluded, the behavior of this feature may see breaking changes even in minor releases. We recommend using this feature only in prerelease versions of modules as long as it remains experimental.
Thank you again for all your contributions to Terraform, and we’re so excited for you to try this release.