TF-004 Implement and maintain state Practice Question
Exhibit
$ terraform import aws_instance.web_server i-0a1b2c3d4e5f6g7h8
aws_instance.web_server: Importing from ID "i-0a1b2c3d4e5f6g7h8"...
aws_instance.web_server: Import prepared!
Prepared aws_instance for import
aws_instance.web_server: Refreshing state... [id=i-0a1b2c3d4e5f6g7h8]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
$ terraform state pull
{
"version": 4,
"terraform_version": "1.5.0",
"serial": 1,
"lineage": "abc123",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_instance",
"name": "web_server",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"id": "i-0a1b2c3d4e5f6g7h8",
"ami": "ami-0c55b159cbfafe1f0",
"instance_type": "t2.micro"
}
}
]
}
]
}Refer to the exhibit. After importing an AWS instance, the state file shows the resource. However, the configuration file (main.tf) does not yet contain the resource definition. What will happen when 'terraform plan' is run?
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
✓
It will show a plan to destroy the resource because it exists in state but not in configuration.
Terraform plan compares the state to the configuration. Since the resource exists in state but not in configuration, Terraform will plan to destroy the resource because it is no longer managed (configuration is the source of truth for what should exist).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
It will show a plan to destroy the resource because it exists in state but not in configuration.
Why this is correct
When a resource is present in the Terraform state file but its corresponding definition is absent from the configuration files, Terraform's `plan` command identifies this discrepancy. The configuration explicitly defines the *desired* state of the infrastructure. If a resource exists in the actual infrastructure (and thus in state) but is not desired per the configuration, Terraform will propose to destroy it to align the real world with the declared configuration.
- ✗
It will show a plan to create the resource because the configuration is missing.
Why it's wrong here
Terraform will not plan to create a resource if its configuration is missing. A `create` action is proposed when a resource is defined in the configuration but does not yet exist in the Terraform state file or the actual infrastructure. In this scenario, the resource *is* in state, indicating it already exists, so a creation plan would be illogical and incorrect.
- ✗
It will error because the configuration and state are out of sync.
Why it's wrong here
Terraform is designed to manage infrastructure drift and discrepancies between configuration and state gracefully, not to error out in such common scenarios. While the configuration and state are indeed out of sync, Terraform's `plan` command will successfully compute the necessary actions to bring them into alignment, which in this case involves proposing the destruction of the unmanaged resource rather than halting execution with an error.
- ✗
It will show no changes because the resource is already in state.
Why it's wrong here
Showing no changes would imply that the current state perfectly matches the desired state defined in the configuration. However, with a missing configuration for a resource that exists in state, there is a clear mismatch. Terraform's core function is to reconcile the actual infrastructure (represented by state) with the desired infrastructure (represented by configuration), and a missing configuration signals that the resource is no longer desired, thus necessitating a change (destruction).
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.