When working with Terraform, drift between your Git repository and the local or remote state can cause deployment failures, stale resources, and hard-to-trace bugs. A clean reset aligns code and infrastructure, removes corrupted state, and ensures that execution plans match expectations.
Git Reset for Terraform begins with restoring your repository to a known commit. Use:
git fetch origin
git reset --hard origin/main
This wipes local changes, ensuring the Terraform code is exactly what is stored remotely.
Next, address the Terraform state. If the state file is compromised or outdated, clear it:
terraform state rm <resource_name>
Or, for a full reset:
rm -f terraform.tfstate*
terraform init
For remote backends like S3, GCS, or Terraform Cloud, remove the backend state through provider tools or directly in the service UI before reinitializing. Without this, Terraform will continue referencing legacy infrastructure metadata.
Always run:
terraform plan
to verify that the state and repo match. If the plan output is clean and matches your desired configuration, apply changes:
terraform apply
This workflow—hard Git reset, state cleanup, reinitialization—solves most Terraform drift problems. It’s a direct way to bring the system into alignment and remove hidden errors before they cause outages.
Want to see infrastructure reset and redeploy happen instantly? Try it on hoop.dev and watch it go live in minutes.