How does `optional()` work in object types?
IntermediateConceptVariables, Locals, Outputs and Types
Answer
Since 1.3 you can mark attributes optional and give defaults.
variable "db" {
type = object({
engine = string
size_gb = optional(number, 50)
backup = optional(bool, true)
})
}
Callers can omit size_gb and backup; without a default an omitted optional attribute is null.
More on Variables, Locals, Outputs and Types
How do you declare an input variable?BeginnerIn what order does Terraform load variable values?BeginnerHow do you define an output and what is it for?BeginnerWhat is the difference between locals and variables?BeginnerWhat are the primitive types in Terraform?BeginnerHow do list, set and map differ?Intermediate