Lab 25: Destroying All Terraform Resources¶
- Go to your Terraform project folder (where
main.tfis located):
cd ~/swarm-terraform
- Initialize (only needed if not already initialized):
terraform init
- Run destroy with confirmation prompt:
terraform destroy
Terraform will show you a plan of what will be deleted and ask:
Do you really want to destroy all resources? Enter a value: yes
- To skip the confirmation prompt (use with care):
terraform destroy -auto-approve
✅ This will remove:
- EC2 instances (manager + workers)
- Security groups
- VPC, subnets, route tables, internet gateway
- Key pair (if created by Terraform)
⚠️ Important for students:
- Always run
terraform destroyfrom the same folder where you ranterraform apply(so it uses the sameterraform.tfstate). - Double-check the AWS Console afterwards to ensure no stray resources (like EBS volumes or elastic IPs) remain.