Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add potential support other cloud providers #22

Merged
merged 5 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# cloud-nuke

This repo contains a CLI tool to delete all AWS resources in an account. cloud-nuke was created for situations when you might have an account you use for testing and need to clean up left over resources so AWS doesn't charge you for them. Also great for cleaning out accounts with redundant resources.
This repo contains a CLI tool to delete all cloud (AWS, Azure, GCP) resources in an account. cloud-nuke was created for situations when you might have an account you use for testing and need to clean up left over resources so you're not charged for them. Also great for cleaning out accounts with redundant resources.

The currently supported functionality includes:

## AWS

* Deleting all Auto scaling groups in an AWS account
* Deleting all Elastic Load Balancers (Classic and V2) in an AWS account
* Deleting all EBS Volumes in an AWS account
* Deleting all unprotected EC2 instances in an AWS account
* Deleting all AMIs in an AWS account
* Deleting all Snapshots in an AWS account

## Azure

_Coming Soon_

## GCP

_Coming Soon_

### WARNING: THIS TOOL IS HIGHLY DESTRUCTIVE, ALL SUPPORTED RESOURCES WILL BE DELETED. ITS EFFECTS ARE IRREVERSIBLE AND SHOULD NEVER BE USED IN A PRODUCTION ENVIRONMENT

## Install
Expand All @@ -22,7 +32,7 @@ The currently supported functionality includes:

## Usage

Simply running `cloud-nuke` will start the process of cleaning up your AWS account. You'll be shown a list of resources that'll be deleted as well as a prompt to confirm before any deletion actually takes place.
Simply running `cloud-nuke <provider>` (e.g. `cloud-nuke aws`) will start the process of cleaning up your cloud account. You'll be shown a list of resources that'll be deleted as well as a prompt to confirm before any deletion actually takes place.

### Excluding Regions

Expand All @@ -44,6 +54,8 @@ Happy Nuking!!!

## Credentials

### AWS

In order for the `cloud-nuke` CLI tool to access your AWS, you will need to provide your AWS credentials. You can used one of the [standard AWS CLI credential mechanisms](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html).

## Running Tests
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- checkout
- attach_workspace:
at: /go/src/github.com/gruntwork-io/cloud-nuke
- run: go run main.go --older-than 24h --exclude-region us-west-2 --force
- run: go run main.go aws --older-than 24h --exclude-region us-west-2 --force

deploy:
<<: *defaults
Expand Down
29 changes: 27 additions & 2 deletions commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func CreateCli(version string) *cli.App {
app.HelpName = app.Name
app.Author = "Gruntwork <www.gruntwork.io>"
app.Version = version
app.Usage = "A CLI tool to cleanup AWS resources (ASG, ELB, ELBv2, EBS, EC2, AMI, Snapshots). THIS TOOL WILL COMPLETELY REMOVE ALL RESOURCES AND ITS EFFECTS ARE IRREVERSIBLE!!!"
app.Usage = "A CLI tool to cleanup cloud resources (ASG, ELB, ELBv2, EBS, EC2, AMI, Snapshots). THIS TOOL WILL COMPLETELY REMOVE ALL RESOURCES AND ITS EFFECTS ARE IRREVERSIBLE!!!"
app.Flags = []cli.Flag{
cli.StringSliceFlag{
Name: "exclude-region",
Expand All @@ -40,7 +40,7 @@ func CreateCli(version string) *cli.App {
},
}

app.Action = errors.WithPanicHandling(awsNuke)
app.Action = errors.WithPanicHandling(cloudNuke)
return app
}

Expand All @@ -58,6 +58,31 @@ func parseDurationParam(paramValue string) (*time.Time, error) {
}

// Nuke it all!!!
func cloudNuke(c *cli.Context) error {
if c.NArg() > 0 {
providers := []string{"aws", "azure", "gcp"}
provider := c.Args().Get(0)
if collections.ListContainsElement(providers, provider) {
switch provider {
case "aws":
return awsNuke(c)
case "azure":
return UnsupportedProviderError{
Name: "azure",
}
case "gcp":
return UnsupportedProviderError{
Name: "gcp",
}
}
}

return UnsupportedProviderError{}
}

return cli.ShowAppHelp(c)
}

func awsNuke(c *cli.Context) error {
regions := aws.GetAllRegions()
excludedRegions := c.StringSlice("exclude-region")
Expand Down
12 changes: 12 additions & 0 deletions commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ type InvalidFlagError struct {
func (e InvalidFlagError) Error() string {
return fmt.Sprintf("Invalid value %s for flag %s", e.Value, e.Name)
}

type UnsupportedProviderError struct {
Name string
}

func (e UnsupportedProviderError) Error() string {
if e.Name == "" {
return fmt.Sprintf("Invalid cloud provider specified. Possible values aws | azure | gcp")
}

return fmt.Sprintf("%s is not currently supported by cloud-nuke", e.Name)
}