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?
Think about what the state file represents versus the real resource.
The terraform state rm command removes the resource from Terraform's state file. This means Terraform no longer tracks it, but the actual resource in the cloud remains untouched. Terraform will not manage or delete it unless you import it back or manually delete it.
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?
Focus on the command that only affects the state file.
terraform state rm aws_instance.example removes the resource from the state file only. The other commands either destroy, replace, or import resources, which is not what is asked.
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?
Think about how Terraform compares state and configuration.
When a resource is removed from state but still exists in configuration, Terraform treats it as needing creation. So on terraform apply, it will try to create it again.
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?
Consider what happens when Terraform no longer manages a resource.
Removing a resource from state means Terraform no longer tracks it. Manual changes or drift can happen without Terraform detecting them, which is risky for sensitive resources.
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?
Think about how Terraform tracks resources across workspaces.
Each workspace has its own state. To stop managing a resource in one workspace but keep it in another, remove it from the first workspace's state and import it into the second workspace's state.