0
0
Terraformcloud~5 mins

Terraform state rm for removing resources - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the terraform state rm command do?
It removes a resource from Terraform's state file without deleting the actual resource in the cloud or infrastructure.
Click to reveal answer
intermediate
Why would you use terraform state rm instead of terraform destroy?
Because terraform state rm only removes the resource from Terraform's tracking, leaving the resource intact, while terraform destroy deletes the resource from the infrastructure.
Click to reveal answer
beginner
What is a common use case for terraform state rm?
When a resource is deleted manually outside Terraform, and you want to remove it from the state file to avoid errors during future Terraform runs.
Click to reveal answer
beginner
How do you specify which resource to remove using terraform state rm?
You provide the resource address, like terraform state rm aws_instance.example, where aws_instance.example is the resource address in the state.
Click to reveal answer
intermediate
What should you be careful about when using terraform state rm?
Removing a resource from state means Terraform no longer manages it, so changes or deletions to that resource won't be tracked or applied by Terraform.
Click to reveal answer
What happens to the actual cloud resource when you run terraform state rm?
AThe resource remains in the cloud but is removed from Terraform's state.
BThe resource is deleted from the cloud.
CTerraform updates the resource configuration.
DTerraform backs up the resource.
Which command would you use to delete a resource both from Terraform and the cloud?
Aterraform state rm
Bterraform destroy
Cterraform apply
Dterraform init
If a resource was deleted manually outside Terraform, what should you do to avoid errors in Terraform runs?
ANothing, Terraform will handle it automatically.
BRun <code>terraform apply</code> immediately.
CRun <code>terraform init</code> again.
DRun <code>terraform state rm</code> for that resource.
How do you specify the resource to remove in terraform state rm?
ABy resource ID in the cloud provider console.
BBy resource tag.
CBy resource address in Terraform state, like <code>aws_instance.example</code>.
DBy resource type only.
What is a risk of using terraform state rm carelessly?
ATerraform will lose track of the resource and not manage future changes.
BTerraform might delete the resource accidentally.
CTerraform will crash during apply.
DThe resource will be duplicated.
Explain what terraform state rm does and when you would use it.
Think about managing Terraform's knowledge of resources versus the actual resources.
You got /4 concepts.
    Describe the difference between terraform state rm and terraform destroy.
    One affects Terraform's tracking, the other affects the real resource.
    You got /4 concepts.