How can I solve the issue of terraforming removal from the state?
There was a scenario when I was managing the infrastructure with Terraform, I decided to de-provision a resource by using the technique of removing it. However, during the process, I encountered an issue related to the process of removing, thus the state still contained the reference to the resource which I wanted to eliminate. How can I troubleshoot this particular issue?
In the context of AWS, if you are getting the issue with terraform remove from state, then you should follow several points which are given below:-
Identify the Resource
First, try to analyze your terraform configuration to pinpoint the resource that needs to be removed. Then try to understand the resource type or even name in the context of terraform.
Use terraform state rm
You can use the following command for removing the Identified resources from the state of terraform:-
Terraform state rm .
Refresh and apply
Now use the following command for refreshing and applying the terraform changes:-
“ terraform refresh
terraform apply”
This will trigger the synchronization process which will ensure that the infrastructure aligns with the desired state.
Verify removal
Now you can validate the removal of the resource by using the technique of inspection of your cloud provider’s console.