What I do
Destroy all resources managed by Terraform:
- •Remove Azure resources in correct dependency order
- •Update state file to reflect destroyed resources
- •Handle resource dependencies automatically
When to use me
Use this skill when:
- •Tearing down development/test environments
- •Cleaning up unused infrastructure
- •Recreating infrastructure from scratch
- •Decommissioning a project
Commands
bash
# Interactive destroy (prompts for confirmation) terraform destroy # Auto-approve (DANGEROUS - use with extreme caution) terraform destroy -auto-approve # Target specific resources only terraform destroy -target=azurerm_virtual_machine.main # Plan the destroy first terraform plan -destroy -out=destroy.tfplan terraform apply destroy.tfplan
Safety Checklist
Before destroying:
- • Verify you are in the correct directory
- • Confirm the correct workspace/environment
- • Check
terraform.tfvarsfor environment - • Backup any important data from resources
- • Ensure state file is backed up
- • Review destroy plan carefully
Protection Mechanisms
- •Lifecycle prevent_destroy
hcl
resource "azurerm_resource_group" "main" {
lifecycle {
prevent_destroy = true
}
}
- •Azure Resource Locks - Apply locks to critical resources
Recovery
If accidentally destroyed:
- •State file backup can help identify what was lost
- •Azure Activity Log shows deleted resources
- •Some resources have soft-delete (Key Vault, Storage)