0
0
Terraformcloud~20 mins

Terraform state rm for removing resources - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What happens when you run terraform state rm on a resource?

You have a resource managed by Terraform. You run terraform state rm <resource_name>. What is the immediate effect on Terraform's behavior?

ATerraform deletes the actual resource from the cloud provider immediately.
BTerraform marks the resource as tainted and plans to recreate it on next apply.
CTerraform locks the state file to prevent changes to the resource.
DTerraform removes the resource from its state file but does not delete the actual resource.
Attempts:
2 left
💡 Hint

Think about what the state file represents versus the real resource.

Configuration
intermediate
2:00remaining
Which command correctly removes a resource named aws_instance.example from Terraform state?

You want to remove the resource aws_instance.example from Terraform's state without deleting the actual instance. Which command should you run?

Aterraform destroy -target=aws_instance.example
Bterraform state rm aws_instance.example
Cterraform apply -replace=aws_instance.example
Dterraform import aws_instance.example
Attempts:
2 left
💡 Hint

Focus on the command that only affects the state file.

service_behavior
advanced
2:00remaining
After running terraform state rm on a resource, what will happen if you run terraform apply without changing configuration?

You removed a resource from Terraform state using terraform state rm. You did not change your Terraform configuration files. What will Terraform do when you run terraform apply next?

ATerraform will recreate the resource because it is missing from the state but present in configuration.
BTerraform will do nothing because the resource is removed from state and configuration.
CTerraform will show an error about missing resource in state.
DTerraform will delete the resource from the cloud provider automatically.
Attempts:
2 left
💡 Hint

Think about how Terraform compares state and configuration.

security
advanced
2:00remaining
What is a potential risk of using terraform state rm on sensitive resources?

You use terraform state rm to remove a sensitive resource like a database instance from Terraform state. What risk does this pose?

ATerraform will automatically delete the resource after state removal.
BTerraform will encrypt the resource data in the state file.
CTerraform will lose track of the resource, so accidental manual changes may go unnoticed.
DTerraform will expose sensitive data in logs after removal.
Attempts:
2 left
💡 Hint

Consider what happens when Terraform no longer manages a resource.

Architecture
expert
3:00remaining
You want to remove a resource from Terraform state but keep it managed by another Terraform workspace. What is the best approach?

You have a resource managed in Terraform workspace dev. You want to remove it from dev state but keep managing it in workspace prod. How should you proceed?

ARun <code>terraform state rm</code> in <code>dev</code> workspace and import the resource into <code>prod</code> workspace.
BDelete the resource manually and recreate it in <code>prod</code> workspace.
CRun <code>terraform destroy</code> in <code>dev</code> workspace and then create in <code>prod</code>.
DCopy the state file from <code>dev</code> to <code>prod</code> and run <code>terraform apply</code>.
Attempts:
2 left
💡 Hint

Think about how Terraform tracks resources across workspaces.