Terraform Associate 004 ยท Dependencies, validation and sensitive data
Implicit and explicit dependencies
Dependency graph from references, depends_on and when it is needed, parallelism of independent resources (4f).
Key points
- Terraform builds a dependency graph.
- Referencing another object's attribute (aws_vpc.main.id) creates an implicit dependency and fixes the order. depends_on adds an explicit dependency for hidden relationships with no reference; use it as a last resort because it can make plans more conservative.
- Objects with no path between them in the graph can be processed in parallel.
Source: https://developer.hashicorp.com/terraform/language/meta-arguments/depends_on
Practice questions
How does Terraform normally learn that resource B must be created after resource A?
- B contains an expression that references an attribute of A
- A is declared above B in the same file
- A's file name sorts earlier alphabetically
- B's resource label is longer than A's
Show answer
Answer: A. B contains an expression that references an attribute of A
Expression references between objects form the dependency graph. File order and naming have no effect on ordering.
Which statements about depends_on are true?
- It is meant for relationships that no attribute reference expresses
- It can cause more values to show as known after apply
- Its list may contain arbitrary expressions such as conditionals
- It is required between every two resources in a configuration
- It is valid only inside resource blocks
Show answer
Answer: A. It is meant for relationships that no attribute reference expresses, B. It can cause more values to show as known after apply
It is meant for hidden dependencies and can make plans more conservative. It accepts references to resources or modules, not arbitrary expressions, and works in more than resource blocks.
Terraform always creates resources in the order their blocks appear in the configuration files.
Show answer
Answer: False
False. Order comes from the dependency graph. Objects with no dependency path between them can be handled in parallel regardless of file position.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
