Terraform state is simple when you work alone and a nightmare when five teams share it. Here is the complete guide to remote backends, locking, and drift management at scale.
Run terraform state list to identify partially created resources, then use terraform import to pull any successfully created cloud resources back into state. For resources that failed mid-creation, manually delete them from the cloud provider console first, then re-run terraform apply. Never run terraform destroy after a partial apply without first reconciling state, as it may target unintended resources.
Use terraform state mv to rename or reorganize resource addresses within state before updating module references in HCL. This preserves resource IDs and prevents Terraform from destroying and recreating resources due to address changes. Run terraform plan after every state mv to verify the plan shows zero resource changes before committing the refactored module code.
Discussion0