Question 304 of 428
TF-004 Use the core Terraform workflow Practice Question
During 'terraform apply', a user receives an error: 'Error: Error creating resource: Resource already exists'. The resource does not appear in the Terraform state. What is the most likely cause?
⚠ Common exam trap
HashiCorp often tests the misconception that 'terraform refresh' can fix state drift issues like this, but refresh only updates existing state attributes—it does not import unmanaged resources into the state, so the apply will still fail.
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
✓
The resource was manually created outside of Terraform before the apply.
The error 'Resource already exists' indicates that the resource was created outside of Terraform's management (e.g., manually via the cloud console or CLI). Since the resource does not appear in the Terraform state, Terraform attempts to create it during 'terraform apply', but the underlying API rejects the request because the resource already exists in the cloud provider. This is a common state drift scenario where the real-world infrastructure is out of sync with the Terraform state.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The state file was migrated from a different backend and the resource is duplicated.
Why it's wrong here
State file migration primarily involves moving the metadata about managed resources from one backend location to another, not duplicating the resources themselves within the state or in the cloud provider. If a resource were truly duplicated within the state, Terraform would likely report a conflict during planning or an inability to manage the resource, rather than receiving a 'resource already exists' error from the cloud provider during a creation attempt. This error specifically indicates Terraform is trying to create something that already exists in the target environment.
- ✗
The resource was removed from the configuration but not from state.
Why it's wrong here
If a resource is present in the Terraform state file but subsequently removed from the configuration files, Terraform's plan will identify this resource as no longer desired. During the `terraform apply` operation, Terraform would then attempt to *destroy* this resource from the cloud provider environment to align with the updated configuration. This scenario would lead to a deletion action, not a failure to create due to the resource already existing.
- ✗
The user forgot to run terraform refresh before apply.
Why it's wrong here
`terraform refresh` updates the state file to reflect the current attributes of resources *already managed* by Terraform, detecting any drift from the last known state. It does not, however, discover or import resources that were created manually outside of Terraform and are therefore not present in the state file. Consequently, omitting `terraform refresh` would not prevent Terraform from attempting to create a resource it believes is missing, leading to the 'resource already exists' error if a manual creation occurred.
- ✓
The resource was manually created outside of Terraform before the apply.
Why this is correct
When Terraform executes `terraform apply`, it compares the desired state defined in the configuration with the known state recorded in its state file. If a resource is defined in the configuration but is entirely absent from the state file, Terraform assumes this resource needs to be provisioned. If an identical resource, perhaps with the same unique name or identifier, was previously created directly within the cloud provider environment, the cloud API will reject Terraform's creation request, resulting in an 'already exists' error.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.