Recall & Review
beginner
What does it mean when an attribute in a Terraform object type is optional?
An optional attribute means you do not have to provide a value for it when defining the object. Terraform will accept the object without that attribute.
Click to reveal answer
beginner
How do you declare an optional attribute in a Terraform object type?
Use the syntax
optional(type) for the attribute's type inside the object definition. For example: optional(string).Click to reveal answer
intermediate
What happens if you omit an optional attribute in a Terraform object when applying a configuration?
Terraform uses the default value if provided, or treats the attribute as absent without error if no default is set.
Click to reveal answer
intermediate
Can optional attributes in Terraform objects have default values?
Yes, optional attributes can have default values defined in the variable declaration, which Terraform uses if the attribute is not set.
Click to reveal answer
beginner
Give an example of a Terraform object type with one required and one optional attribute.
Example:
object({ name = string, age = optional(number) }) Here, name is required and age is optional.Click to reveal answer
How do you mark an attribute as optional in a Terraform object type?
✗ Incorrect
In Terraform, optional attributes are declared with
optional(type) inside the object type.What happens if you omit an optional attribute in a Terraform object without a default value?
✗ Incorrect
Terraform treats omitted optional attributes without defaults as absent and does not throw an error.
Which of these is a valid Terraform object type with an optional attribute?
✗ Incorrect
Option A correctly uses
optional(string) to mark 'description' as optional.Can optional attributes in Terraform objects have default values?
✗ Incorrect
Optional attributes can have default values which Terraform uses if the attribute is not provided.
If an attribute is not marked optional in a Terraform object type, what does that mean?
✗ Incorrect
Attributes not marked optional are required and must be provided.
Explain how to define an optional attribute in a Terraform object type and what happens if it is omitted.
Think about how Terraform handles missing values in objects.
You got /3 concepts.
Describe a practical example where optional attributes in Terraform objects are useful.
Consider a resource that sometimes needs extra info but not always.
You got /3 concepts.