From fa0a13e541d3d44106e1f341e1987e930eabaed9 Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Tue, 20 Mar 2018 13:32:59 +0100 Subject: [PATCH 1/5] update cli entrypoint to accept cloud providers as arguments --- commands/cli.go | 27 +++++++++++++++++++++++++-- commands/errors.go | 12 ++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/commands/cli.go b/commands/cli.go index ed04dfc3..d5f295dd 100644 --- a/commands/cli.go +++ b/commands/cli.go @@ -23,7 +23,7 @@ func CreateCli(version string) *cli.App { app.HelpName = app.Name app.Author = "Gruntwork " 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", @@ -40,7 +40,7 @@ func CreateCli(version string) *cli.App { }, } - app.Action = errors.WithPanicHandling(awsNuke) + app.Action = errors.WithPanicHandling(cloudNuke) return app } @@ -58,6 +58,29 @@ 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: "aws", + } + } + } + } + + return UnsupportedProviderError{} +} + func awsNuke(c *cli.Context) error { regions := aws.GetAllRegions() excludedRegions := c.StringSlice("exclude-region") diff --git a/commands/errors.go b/commands/errors.go index 2eadde52..82e9578f 100644 --- a/commands/errors.go +++ b/commands/errors.go @@ -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) +} From f4120a048c791a1f73a66bd594a8f74c2b5fb85e Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Tue, 20 Mar 2018 13:37:06 +0100 Subject: [PATCH 2/5] update README.md to indicate potential addition of new providers --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df3e5c67..3964ec28 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # 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 @@ -11,6 +13,14 @@ The currently supported functionality includes: * 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 @@ -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 ` (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 @@ -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 From 2d29008bb7282bd5109a88fbabbf659e2e971230 Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Tue, 20 Mar 2018 13:37:58 +0100 Subject: [PATCH 3/5] update circle config, specify aws provider for nightly build --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index b4891772..0f54d491 100644 --- a/circle.yml +++ b/circle.yml @@ -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 From 635640d4d4e68d11c894e81f3d64e21f3a02bfce Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Tue, 20 Mar 2018 15:03:19 +0100 Subject: [PATCH 4/5] show usage text when no cloud provider is specified --- commands/cli.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/cli.go b/commands/cli.go index d5f295dd..d0ba9354 100644 --- a/commands/cli.go +++ b/commands/cli.go @@ -76,9 +76,11 @@ func cloudNuke(c *cli.Context) error { } } } + + return UnsupportedProviderError{} } - return UnsupportedProviderError{} + return cli.ShowAppHelp(c) } func awsNuke(c *cli.Context) error { From 44ca79300d4c05378ab1630e8f9e8143fd288497 Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Tue, 20 Mar 2018 15:04:04 +0100 Subject: [PATCH 5/5] fix slight issue with wrong provider name --- commands/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/cli.go b/commands/cli.go index d0ba9354..6fd8624d 100644 --- a/commands/cli.go +++ b/commands/cli.go @@ -72,7 +72,7 @@ func cloudNuke(c *cli.Context) error { } case "gcp": return UnsupportedProviderError{ - Name: "aws", + Name: "gcp", } } }