How To Use Cloud Nuke?

Reading Time: 3 minutes

So if we talk about Infrastructure as a Code(IAC), we know it is the best way to bundle your infra as a code. And for that purpose, we generally use terraform as it is easy and open source and used by folks worldwide. Sometimes we forget to clean up the resources we have created in our cloud environment and that may lead up to using the resources unnecessarily and huge bills. And here terraform lacks to perform clean-up on your platform and that is where Cloud Nuke comes as a savior. But it only works for AWS. So let’s see how Cloud Nuke works for AWS.

Cloud Nuke from Gruntworks-io

How to install Cloud-Nuke on Linux?

For installation, you can visit the release page of Cloud Nuke. You can just download the package from the page.

Download the latest package according to your OS. I have used the amd64 package.

Then move the package to the following path by using the following command mv cloud-nuke_linux_amd64 /usr/local/bin/cloud-nuke.

Then you have to give executable permissions to the package by using the following command chmod u+x /usr/local/bin/cloud-nuke.

Cloud Nuke

To confirm the installation, just type the command in your terminal cloud-nuke –help.

Configuring AWS Account

You have to configure your local system for AWS credentials with an access key and secret access key. You have to type aws configure on your terminal. You’ll find the above creds in Security Credentials >> Access Keys(access key ID and secret access key) in your AWS account.

Checking for the Resources left in the cloud

Before deleting everything from the cloud, we should see what are resources left in there and what will be deleted. So for that, run the below command:

cloud-nuke inspect-aws
Cloud Nuke

The below resources will be checked in all the regions available in your AWS account.

Cloud Nuke

If there is something in there, then it will show you the resources being used there.

Deleting the resources

For deleting the resources from AWS, you just have to type the below command into your terminal:

cloud-nuke aws

So after running the above command, it will again check for the resources being used in the cloud and in all the regions. And after it asks for confirmation to delete all the active resources in the cloud.

Cloud Nuke

In the above image, we can see that all active resources have been removed from the cloud. For more info on cloud-nuke, you guys can visit the Gruntworks GitHub page.

Written by 

Shubham Saini is a DevOps Engineer who loves to play with DevOps tools, Security methods and is also interested in Ethical Hacking & Cyber Security. He is a gamer also.