TF-004 Read, generate and modify configuration Practice Question
Which TWO scenarios require the use of the depends_on argument?
⚠ Common exam trap
HashiCorp Terraform often tests the misconception that any cross-resource reference requires depends_on, when in fact Terraform automatically infers dependencies from direct attribute references, and depends_on is only needed for non-attribute-based or provisioner-created dependencies.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
When a provisioner creates resources that other resources depend on.
When a provisioner (such as a local-exec or remote-exec) creates resources outside of Terraform's state, Terraform cannot automatically detect the dependency. The depends_on argument explicitly tells Terraform to wait for that provisioner-created resource before proceeding. Option C is correct because depends_on is the mechanism to declare a dependency when Terraform's resource graph analysis cannot infer an implicit dependency from attribute references.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
When a resource uses the output of another resource in its arguments.
Why it's wrong here
When a resource uses the output of another resource in its arguments, Terraform's dependency graph automatically infers the correct creation order. For instance, if an aws_instance resource references the id attribute of an aws_vpc resource, Terraform understands that the VPC must be created and its ID available before the instance can be provisioned within it. This implicit dependency mechanism is fundamental to how Terraform manages resource relationships and ensures proper sequencing without manual intervention.
- ✓
When a provisioner creates resources that other resources depend on.
Why this is correct
Provisioners execute arbitrary scripts or commands on a resource, often interacting with external systems or creating entities that Terraform itself does not manage directly. Because Terraform cannot introspect or track the side effects of these external operations, any subsequent Terraform-managed resource that relies on an outcome of a provisioner's execution will not have an automatically inferred dependency. In such cases, an explicit depends_on argument is essential to force the correct ordering, ensuring the provisioner completes its task before dependent resources are evaluated.
- ✓
When Terraform cannot automatically infer an implicit dependency.
Why this is correct
Terraform's primary method for determining resource creation and update order is by analyzing attribute references within the configuration. However, there are specific scenarios where a logical dependency exists between resources, but no direct attribute reference links them. For example, if resource A needs resource B to be fully operational before it can start, but A doesn't consume any output from B, Terraform cannot infer this. The depends_on argument provides a manual override to explicitly declare such a dependency, ensuring B is applied before A.
- ✗
When a resource uses the output of a data source in its arguments.
Why it's wrong here
When a resource uses the output of a data source in its arguments, Terraform automatically establishes an implicit dependency. Data sources are designed to fetch information about existing infrastructure or external services *before* resources are created or updated. Therefore, if a resource configuration references an attribute from a data source, Terraform ensures the data source is successfully read and its outputs are available before attempting to configure the dependent resource, guaranteeing the necessary information is present.
- ✗
When a resource uses a module output as an input.
Why it's wrong here
Referencing an output from a child module as an input to a resource in a parent or sibling module creates an implicit dependency that Terraform automatically resolves. Modules encapsulate configurations, and their outputs are only available after the module's resources have been successfully provisioned. Terraform ensures that the child module is applied and its outputs computed before any resource in the calling module attempts to use those outputs, maintaining the correct execution order across module boundaries.
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.