Nuke Your Cloud
This weekend I am spending some time messing around with AWS and Terraform.
It’s really easy to get started with Terraform, and spin up a bunch of AWS resources.
In fact this is all it takes to create a new EC2 instance.
# main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-west-1"
}
resource "aws_instance" "my_instance" {
ami = "ami-04f7a54071e74f488"
instance_type = "t2.micro"
}
With the AWS CLI setup, simply running
terraform init, terraform plan and terraform apply will deploy this
resource.
The Problem
I’m just messing around with a test project. I am spinning up difference sources just to see what get’s created.
But when it comes to tearing things down, terraform destroy doesn’t always
completely remove everything that gets made.
There’s often a bunch of other “stuff” left over. Security groups, subnets, all sorts.
And I don’t want to have to go throuhg all of my AWS resources to delete that stuff. Maybe it doesn’t matter. Maybe they’re 100% free… But wouldn’t it be nice if there was a way to just delete everything?
Enter Cloud Nuke
This is the tool for the job. Simply run brew install cloud-nuke, and then
cloud-nuke aws and watch it go to work.
Obviously it goes without saying: make sure you’re running this on the right AWS account. Please don’t nuke something important.
You’ll likely want to only have cloud-nuke search the region that you care
about, otherwise a full scan can take upwards of 30+ minutes.
That’s it. Quick and easy. A great tool for the job.
As always, get busy building.
Marcel van Workum