AgentSkillsCN

tf-destroy

安全销毁由 Terraform 管理的 Azure 基础设施

SKILL.md
--- frontmatter
name: tf-destroy
description: Destroy Terraform-managed Azure infrastructure safely
license: MIT
compatibility: opencode
metadata:
  workflow: terraform
  provider: azure

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.tfvars for environment
  • Backup any important data from resources
  • Ensure state file is backed up
  • Review destroy plan carefully

Protection Mechanisms

  1. Lifecycle prevent_destroy
hcl
resource "azurerm_resource_group" "main" {
  lifecycle {
    prevent_destroy = true
  }
}
  1. 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)