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 prompt for user confirmation and then perform the default destroy-then-create sequence, effectively ignoring the lifecycle block.
OpenTofu will create a new EC2 instance first, and only after it is in service will it destroy the old one, minimizing downtime.
OpenTofu will destroy the existing EC2 instance before creating a new one because the create_before_destroy argument is ignored for EC2 resources.
The create_before_destroy setting is overridden by the dependency on the security group, so both resources are destroyed and recreated in order.
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...
IT & Cybersecurity Package Join Premium for Full Access