HashiCorp Certified: Terraform Associate (004) — Question 2
If you manually destroy resources within your infrastructure, what is the best practice for reflecting this change in Terraform?
Answer options
- A. Run terraform import to reflect the changes in Terraform state.
- B. Manually update the state file to remove the destroyed resources.
- C. Remove the resource definition from your file and run terraform apply -refresh-only.
- D. The change will happen automatically during the next terraform apply.
Correct answer: D
Explanation
The correct answer is D because Terraform automatically detects changes in the infrastructure during the next apply and updates the state accordingly. Option A is incorrect as import is used for bringing existing resources into Terraform management, not for reflecting manual deletions. Option B is not recommended since directly modifying the state file can lead to inconsistencies. Option C would not achieve the intended result, as it does not automatically remove the resources from the state.