TF-004 Implement and maintain state Practice Question
Exhibit
$ terraform state list
aws_instance.web_server
data.aws_ami.ubuntu
aws_security_group.web_sg
$ terraform state show aws_instance.web_server
# aws_instance.web_server:
resource "aws_instance" "web_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
"Name" = "WebServer"
}
subnet_id = "subnet-0a1b2c3d4e5f6g7h8"
vpc_security_group_ids = [
"sg-0a1b2c3d4e5f6g7h8",
]
}
$ terraform plan
No changes. Your infrastructure matches the configuration.
$ terraform state rm aws_instance.web_server
Removed aws_instance.web_server from state.
$ terraform plan
+ create
Terraform will perform the following actions:
# aws_instance.web_server will be created
...Refer to the exhibit. An engineer runs the commands shown in sequence. After executing 'terraform state rm', the next 'terraform plan' shows that the resource will be created. What is the most likely reason?
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 'terraform state rm' command only removes the resource from the state file, not the actual infrastructure. The next plan sees the configuration and attempts to create a new resource.
The 'terraform state rm' command removes the resource from the state file but does not destroy the actual infrastructure. The resource still exists in AWS. The next 'terraform plan' sees that the resource is not in state but the configuration still exists, so it plans to create a new resource with the same configuration.
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 'terraform state rm' command only removes the resource from the state file, not the actual infrastructure. The next plan sees the configuration and attempts to create a new resource.
Why this is correct
The 'terraform state rm' command specifically targets the Terraform state file, removing the record of a managed resource without interacting with the actual cloud provider API to destroy the resource itself. When 'terraform plan' is subsequently executed, it compares the current configuration (which still declares the resource) against the modified state file (which no longer contains the resource's record). This discrepancy leads Terraform to identify the resource as "missing" from its management, prompting a plan to create a new instance to align the infrastructure with the desired configuration.
- ✗
The 'terraform state rm' command triggers an automatic recreation of the resource.
Why it's wrong here
The 'terraform state rm' command is a state manipulation operation that solely modifies the Terraform state file; it does not initiate any API calls to the cloud provider or trigger any infrastructure changes directly. An automatic recreation would imply an immediate 'apply' action, but 'state rm' only prepares the ground for a future 'plan' to detect a drift and propose recreation. This proposed recreation then requires an explicit 'terraform apply' to execute, making the recreation process manual, not automatic.
- ✗
The resource was destroyed by a separate process.
Why it's wrong here
If the resource had been destroyed by a separate process outside of Terraform's management, the 'terraform plan' command would indeed detect its absence and propose to create it, similar to the scenario where 'state rm' is used. However, the core premise of 'terraform state rm' is that the resource *still exists* in the cloud but is no longer tracked by Terraform. The question implies the resource is still present, just untracked, making destruction by a separate process an unsupported assumption inconsistent with the specific action of 'state rm'.
- ✗
The state file was corrupted after removal.
Why it's wrong here
The 'terraform state rm' command is a controlled and atomic operation designed to safely remove specific resource entries from the state file. It performs a structured modification, ensuring the state file's integrity is maintained throughout the process. If the state file were corrupted, Terraform would typically report parsing errors or an invalid state format during subsequent commands like 'plan', rather than simply proposing to create a resource that it no longer tracks due to a clean removal.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.