optional object attribute
Marking an attribute of an object type with optional() so callers may leave it out, with an optional default value.
In more detail
It lets a module accept a rich settings object without forcing every caller to fill in every field. It has been available since Terraform 1.3.
Example
type = object({ name = string, size = optional(number, 2) })Related terms
- type constraint — The type argument of a variable, such as string, number, bool, list(string), map(string) or object({...}), which rejects values of the wrong shape.
- input variable — A named, typed value a configuration or module takes from outside, declared in a variable block and read as var.<name>.
Taught in
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Complex Types: Lists, Sets, Maps, Objects And Tuples — HashiCorp Terraform Associate (004) Exam Prep