Terraform
infrastructure.terraform
Protects against destructive Terraform/OpenTofu operations like destroy, taint, and apply with -auto-approve
- 8blocking rules
- 11safe patterns
- 1Critical
- 5High
- 2Medium
[packs]
enabled = ["infrastructure.terraform"]Evaluated when a command contains terraform, tofu, terragrunt, destroy, taint, state.
Recorded verdicts
terraform destroy -auto-approveBlockedinfrastructure.terraform:destroyterraform planAllowed
Blocking rules
Each rule ID is infrastructure.terraform:<name>. Use it in allowlists and [policy.rules].
Criticaldestroyterraform/tofu destroy removes ALL managed infrastructure. Use 'terraform plan -destroy' first.
Explanation
terraform destroy removes ALL managed infrastructure: - Every resource in your state file is destroyed - Cloud resources (VMs, databases, networks) deleted - Cannot be undone without backups/recreation - Use -target to destroy specific resources only Preview first: terraform plan -destroy
Highapply-auto-approveterraform/tofu apply -auto-approve skips confirmation. Remove -auto-approve for safety.
Explanation
terraform apply -auto-approve skips confirmation: - No opportunity to review changes before applying - Intended for CI/CD, not interactive use - Changes may destroy or recreate resources For safety: remove -auto-approve and review the plan
Highforce-unlockterraform/tofu force-unlock removes state lock. Only use if lock is stale.
Explanation
terraform force-unlock removes state locks: - Forces removal of a state lock - May cause corruption if another process is running - Only use when you're sure no other operation is active - Lock ID required to prevent accidents Verify no other operations: check CI/CD pipelines, other users
Highstate-mvterraform/tofu state mv moves resources in state. Incorrect moves can cause resource recreation.
Explanation
terraform state mv moves resources in state: - Renames resource address in state file - Wrong move can cause destruction/recreation - Use -dry-run to preview the move first - Does not affect actual cloud resources Preview first: terraform state mv -dry-run SOURCE DEST
Highstate-rmterraform/tofu state rm removes resource from state without destroying it. Resource becomes unmanaged.
Explanation
terraform state rm orphans resources: - Resource removed from Terraform state - Actual cloud resource still exists - Resource becomes 'unmanaged' (Terraform ignores it) - May cause drift between state and reality Back up state first: terraform state pull > backup.tfstate
Hightaintterraform/tofu taint marks a resource to be destroyed and recreated on next apply.
Explanation
terraform taint marks resource for recreation: - Resource will be destroyed on next apply - New resource created with same config - May cause downtime during recreation - IP addresses and identifiers may change Use -replace in plan/apply instead (Terraform 0.15.2+)
Mediumplan-destroyterraform/tofu plan -destroy shows what would be destroyed. Review carefully before applying.
Explanation
terraform plan -destroy shows destruction preview: - This is a read-only operation (safe to run) - Shows what WOULD be destroyed if you apply - Review output carefully before proceeding This is actually the safe way to preview destroy.
Mediumworkspace-deleteterraform/tofu workspace delete removes a workspace. Ensure it's not in use.
Explanation
terraform workspace delete removes workspace: - Workspace and its state file deleted - Does NOT destroy actual infrastructure - Resources become unmanaged (orphaned) - Cannot be undone without state backup Destroy resources first: terraform destroy, then delete workspace
Safe patterns
Checked first. A command that matches one is never blocked by this pack.
terraform-planterraform-initterraform-validateterraform-fmtterraform-showterraform-outputterraform-state-listterraform-state-showterraform-graphterraform-versionterraform-providers