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.
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:
The below resources will be checked in all the regions available in your AWS account.
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:
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.
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.