export TF_LOG=TRACETurn on maximum logging detail for hard-to-diagnose issues.
Commands and patterns for debugging, upgrades, migration, and state repair in Terraform.
Logs, provider issues, and plan inspection.
export TF_LOG=TRACETurn on maximum logging detail for hard-to-diagnose issues.
export TF_LOG=DEBUG && export TF_LOG_PATH=terraform-debug.logCapture debug logs into a file for later analysis.
terraform providers schema -json > providers-schema.jsonDump provider schemas for automation or debugging tools.
terraform plan -detailed-exitcodeReturn 0 for no changes, 2 for changes, 1 for errors; useful in CI.
Version-locking and migration-related commands.
Legacy helper command that updated provider source declarations in Terraform 0.13.
terraform 0.13upgradeLegacy helper command that updated provider source declarations in Terraform 0.13.
Refresh provider selections and lock file after changing constraints.
terraform init -upgrade && terraform providers lock -platform=linux_amd64 -platform=darwin_arm64Refresh provider selections and lock file after changing constraints.
moved {
from = module.network.aws_subnet.private["a"]
to = module.vpc.aws_subnet.private["a"]
}Preserve state when refactoring module paths or names.
State surgery patterns for emergencies and refactors.
terraform state show module.vpc.aws_vpc.thisInspect one resource nested inside a module.
terraform state mv module.old.aws_s3_bucket.logs module.new.aws_s3_bucket.logsMove a tracked object between module addresses.
terraform state rm aws_instance.web[0]Remove a single indexed or keyed instance from state.
Recover from drift, failed runs, and manual changes.
terraform plan -refresh-onlyRefresh state from real infrastructure without proposing config changes.
terraform apply -refresh-only -auto-approvePersist refreshed state after infrastructure drift detection.
Rebuild Terraform state associations after state loss or partial migration.
terraform import aws_db_instance.main my-db-instance-idRebuild Terraform state associations after state loss or partial migration.