TF-004 Read, generate and modify configuration Practice Question
A DevOps engineer wants to modify the Terraform configuration to control resource lifecycle behavior. Which TWO meta-arguments can be used to influence the order of creation and destruction?
⚠ Common exam trap
Candidates often confuse meta-arguments that control lifecycle behavior (like `create_before_destroy` and `prevent_destroy`) with those that control resource count or iteration (like `count` and `for_each`). Specifically, `prevent_destroy` does not influence creation/destruction order; it only blocks destruction.
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
✓
create_before_destroy
`create_before_destroy` is a meta-argument used within a `lifecycle` block to instruct Terraform to create a replacement resource before destroying the existing one, directly influencing the order of creation and destruction during updates. Option B is correct because `depends_on` explicitly sets dependencies between resources, ensuring that Terraform creates or destroys resources in a specific order based on those declared dependencies.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
create_before_destroy
Why this is correct
The `create_before_destroy` lifecycle argument is essential for minimizing downtime during resource updates that require replacement rather than in-place modification. When set to `true`, Terraform will provision the new version of the resource, update any dependent resources to point to the new instance, and only then destroy the old resource. This ensures continuous availability and prevents service interruptions during a resource's lifecycle replacement.
- ✓
depends_on
Why this is correct
The `depends_on` meta-argument allows a DevOps engineer to explicitly declare hidden dependencies between resources that Terraform cannot automatically infer from attribute references. This is crucial for ensuring the correct operational order when one resource must be fully provisioned or updated before another, even without a direct data flow. Explicitly setting `depends_on` prevents race conditions and ensures the stability of the infrastructure provisioning process.
- ✗
for_each
Why it's wrong here
The `for_each` meta-argument is used to create multiple instances of a resource or module based on the elements of a map or set of strings, assigning a unique key to each instance. While it provides a flexible way to manage collections of resources dynamically, its sole purpose is for resource instantiation. It does not provide any mechanism to control the creation, update, or destruction order of individual resources or their lifecycle behavior.
- ✗
prevent_destroy
Why it's wrong here
The `prevent_destroy` lifecycle argument, when set to `true`, acts as a critical safety mechanism to protect important resources from accidental or unintended deletion. If a Terraform plan attempts to destroy a resource with this protection enabled, Terraform will return an error, requiring manual intervention to disable it. However, this argument only blocks destruction and has no influence on the order in which resources are created or updated.
- ✗
count
Why it's wrong here
The `count` meta-argument is used to create multiple identical instances of a resource or module, indexed numerically from 0 to `count - 1`. It is suitable for scenarios where a fixed number of similar resources are required. While `count` controls the *number* of instances, it does not provide any mechanism to influence the specific creation, update, or destruction order of those instances relative to each other, nor does it affect the lifecycle behavior of individual resources.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.