TA-002-P · Question #171
TA-002-P Question #171: Real Exam Question with Answer & Explanation
The correct answer is A: No resource will be updated and you will see the message : Apply Complete !. Before applying, Terraform refreshes state against real infrastructure; if the actual state already matches the desired configuration, no changes are made and apply completes with zero updates.
Question
You have created an AWS EC2 instance of type t2.micro through your terraform configuration file ec2.tf . Now you want to change the instance type from t2.micro to t2.medium. Accordingly you have changed your configuration file and and ran terraform plan. After running terraform plan you check the output and saw one instance will be updated from t2.micro --> t2.medium. After this you went to grab a coffee without running terraform apply and meanwhile a member of your team changed the instance type of that EC2 instance to t2.medium from aws console. After coming to your desk you run terraform apply. What will happen?
Options
- ANo resource will be updated and you will see the message : Apply Complete !
- BThe instance type will be changed to t2.micro and again will be changed to t2.medium
- Cterraform apply will through an error.
- D1 resource will be updated and you will see the message : Apply Complete ! Resources :
Explanation
Before applying, Terraform refreshes state against real infrastructure; if the actual state already matches the desired configuration, no changes are made and apply completes with zero updates.
Common mistakes.
- B. Terraform does not revert the instance to t2.micro before re-applying; it compares the refreshed current state to desired state and only acts on actual differences.
- C. Terraform apply does not throw an error when real-world state already matches the desired configuration; the refresh mechanism is designed specifically to handle this scenario gracefully.
- D. No resource is updated because after refreshing, Terraform finds the instance type already equals t2.medium and therefore calculates zero changes.
Concept tested. Terraform state refresh and infrastructure drift handling on apply
Reference. https://developer.hashicorp.com/terraform/cli/commands/apply
Topics
Community Discussion
No community discussion yet for this question.