What are advanced Terraform state management operations?
Answer
Advanced state management operations for production scenarios: terraform state mv: rename a resource in state without destroying it — used when refactoring module structure or renaming resources. terraform state mv module.old.aws_instance.web module.new.aws_instance.web. terraform state rm: remove a resource from state without destroying the actual infrastructure — used when you want to stop managing a resource with Terraform. terraform state pull/push: download or upload state JSON directly — for manual state surgery (last resort). terraform state replace-provider: replace the provider source in state after provider namespace changes. State migration: move state between backends by changing the backend config and running terraform init -migrate-state. Partial state corruption recovery: use state versioning (S3 versioning enabled on the state bucket) to restore a previous state version. Always back up state before any manual state operations.
Previous
What is the Terraform CDK (CDKTF)?
Next
How do you implement a CI/CD pipeline for Terraform?
More Terraform / IaC Questions
View all →- Advanced What is Terraform's provider development and custom providers?
- Advanced What is Policy as Code with Sentinel in Terraform?
- Advanced How does Terraform handle dependencies between resources?
- Advanced What is the Terraform CDK (CDKTF)?
- Advanced How do you implement a CI/CD pipeline for Terraform?