Bitzu

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

Single choice

How does Terraform normally learn that resource B must be created after resource A?

  1. B contains an expression that references an attribute of A
  2. A is declared above B in the same file
  3. A's file name sorts earlier alphabetically
  4. 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.

Select all that apply

Which statements about depends_on are true?

  1. It is meant for relationships that no attribute reference expresses
  2. It can cause more values to show as known after apply
  3. Its list may contain arbitrary expressions such as conditionals
  4. It is required between every two resources in a configuration
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module