During an OpenTofu deployment you need to replace an existing web-server EC2 instance without interrupting service. The current configuration contains:
Later, the AMI ID is updated in version control. When the next tofu apply runs, which statement accurately describes what will happen to the aws_instance.web resource?
OpenTofu will create a new EC2 instance first, and only after it is in service will it destroy the old one, minimizing downtime.
The create_before_destroy setting is overridden by the dependency on the security group, so both resources are destroyed and recreated in order.
OpenTofu will destroy the existing EC2 instance before creating a new one because the create_before_destroy argument is ignored for EC2 resources.
OpenTofu will prompt for user confirmation and then perform the default destroy-then-create sequence, effectively ignoring the lifecycle block.
Setting create_before_destroy = true in the resource's lifecycle block tells OpenTofu to invert its usual replacement order. Instead of destroying the current EC2 instance first and then creating the replacement, OpenTofu launches a new instance, waits until it is available, and only then terminates the original. Because EC2 instances have unique IDs, both instances can coexist temporarily, so downtime is avoided. The other statements are incorrect: the meta-argument is supported for EC2 resources, the dependency on the security group does not override it, and the normal confirmation prompt does not negate the lifecycle behavior.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the `create_before_destroy` lifecycle argument?
Open an interactive chat with Bash
How does OpenTofu handle dependencies, like security groups, during resource updates?
Open an interactive chat with Bash
What specific scenarios benefit from the `create_before_destroy` behavior?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .