TF-004 Read, generate and modify configuration Practice Question
A Terraform plan shows that an AWS EC2 instance will be destroyed and recreated. The team wants to ensure zero downtime during the update. Which lifecycle attribute should be added?
⚠ Common exam trap
Candidates often confuse `create_before_destroy` with `prevent_destroy` or `ignore_changes`, thinking any lifecycle attribute that prevents destruction or ignores changes will solve downtime, when only `create_before_destroy` explicitly ensures the replacement is ready before the original is removed.
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 lifecycle attribute that instructs Terraform to create the replacement resource first, then destroy the old one. This ensures that the new EC2 instance is fully operational before the original is terminated, achieving zero downtime during the update.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
depends_on
Why it's wrong here
The depends_on meta-argument establishes explicit ordering between resources, ensuring that a target resource is created only after its dependencies are fully provisioned, or destroyed before them. However, it governs the sequence of operations *between* distinct resources, not the specific create-then-destroy sequence for a *single* resource undergoing a replacement due to configuration changes. It does not force a new instance to be created before an old one is terminated, which is the core problem this question addresses.
- ✗
ignore_changes
Why it's wrong here
The ignore_changes lifecycle rule prevents Terraform from detecting and applying modifications to specified resource attributes, effectively making those attributes immutable from Terraform's perspective after initial creation. While it can prevent a resource from being marked for replacement if the change is solely within an ignored attribute, it does not alter the default destroy-then-create order when a resource *is* slated for replacement due to changes in *other*, non-ignored attributes. Therefore, it doesn't solve the problem of ensuring a new instance exists before the old one is destroyed.
- ✓
create_before_destroy
Why this is correct
The create_before_destroy lifecycle rule explicitly instructs Terraform to provision the new version of a resource entirely *before* initiating the destruction of the old version when a replacement is necessary. This critical behavior is designed to minimize or eliminate downtime for services by ensuring the updated resource is fully operational and ready to serve traffic before its predecessor is taken offline. It directly addresses the need to maintain continuous availability during resource updates that require recreation, such as an EC2 instance replacement.
- ✗
prevent_destroy
Why it's wrong here
The prevent_destroy lifecycle rule acts as a safeguard, completely blocking Terraform from destroying the associated resource under any circumstances, even if the configuration changes would normally necessitate its removal. While invaluable for protecting critical infrastructure from accidental deletion, this rule makes it impossible to perform updates that require a resource to be replaced (destroyed and then recreated). Consequently, it is unsuitable for scenarios where a resource needs to be updated with zero downtime via a create-before-destroy mechanism, as it would prevent the necessary destruction step.
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.