I am using terraform cloud, cli driven workspace with remote mode. My question is how can I restore azure resources to previous state ?
For example a simple resource group with location “eastus” changed to “westus” with terraform apply and now i want to restore back to “eastus” but not to change in script and re apply terraform.
can this be done from terraform state restoration ?
The Terraform code defines the state you are wanting, so if something has changed to be different to what you are desiring that suggests the code is incorrect. You’d change that code and then rerun Terraform to apply the corrected values.
what would be use case to use " Rollback to this State Version" ?
The scenario I am testing -
1- created a resource group ( from terraform apply)
2- Rollback to this State Version ( From terraform cloud portal state)
3- terraform plan same resource group ( plan is successful since no resource in tfstate)
Since resource exists on Azure but not in tfstate and that completely make sense as well, since tfstate rollback can’t change actual cloud resource, hence wondering use cases about this option.
When you say rollback state version are you meaning that you are storing the Terraform state in a system which stores versioned snapshots whenever it changes, and you are talking about recovering one of these previous backups?
If so, this is not something you would normally do. The most common usage is if you are doing a major upgrade to a version of Terraform or a provider and something goes wrong, allowing you to switch to the previous state - during which nothing would have happened to the underlying resources.
If you recover a state file backup after doing a
terraform apply that has changed state you will now be totally out of sync with reality, meaning you’d need to do
terraform import or
terraform state rm commands to fix.