jckuester / awsweeper

A tool for cleaning your AWS account
Mozilla Public License 2.0
468 stars 45 forks source link

adding ECS Cluster option #65

Closed siran closed 4 years ago

siran commented 4 years ago

More than a pull request, I wanted to ask for you to please review this commit. I intent to add support for ECS CLUSTER deletion, but after adding all obvious changes and executing [1], I get the error [2].

[1] Create a file cluster.yml:

aws_ecs_cluster:

Build this commit and execute as:

$ ./awsweeper --dry-run clusters.yml

If you have ECS Clusters on you AWS account, you should see an error similar to:

goroutine 1 [running]:
reflect.Value.Len(0x3e928e0, 0xc00067c360, 0x16, 0x3e92840)
    /usr/local/go/src/reflect/value.go:1150 +0x1a6
github.com/cloudetc/awsweeper/resource.DeletableResources(0xc0006530c0, 0xf, 0x3e928e0, 0xc00067c360, 0xc00067c360, 0x0, 0x0, 0xc000109a20, 0x0)
    /my/path/to//awsweeper/resource/resource.go:17 +0x126
github.com/cloudetc/awsweeper/command.Info(0xc0000421c0, 0x43b02bd, 0x5)
    /my/path/to//awsweeper/command/wipe.go:39 +0x157
github.com/cloudetc/awsweeper/command.(*Wipe).Run(0xc0000421c0, 0xc0003549b0, 0x1, 0x1, 0xc000042180)
    /my/path/to//awsweeper/command/wipe.go:68 +0x145
github.com/mitchellh/cli.(*CLI).Run(0xc0003e4000, 0xc00086ccf0, 0x43af4b4, 0x4)
    /Users/anmichelr/go/pkg/mod/github.com/mitchellh/cli@v0.0.0-20180117155440-518dc677a1e1/cli.go:255 +0x1da
github.com/cloudetc/awsweeper/command.WrappedMain(0xc0000b0058)
    /my/path/to//awsweeper/command/wrapped_main.go:99 +0x9a2
main.main()
    /my/path/to//awsweeper/main.go:14 +0x22

(disclaimer: I'm totally new to Go)

jckuester commented 4 years ago

One more thing: When I started this AWSweeper project (and when I was new to Go) I statically imported the Terraform AWS Provider to delete resources. I guess, at that time ECS didn't exist, so I think we can currently not delete ECS clusters (and I cannot import a newer version of the provider statically).

However, I am working on a new approach to dynamically use the latest Terraform AWS Provider as a plugin to always be able to delete also the newest resources (see: https://github.com/jckuester/terradozer). I just need some time to integrate that deletion approach here.

siran commented 4 years ago

You mean by this that ECS can't be deleted with the current implementation of awsweeper?

siran commented 4 years ago

Also, terradozer seems very useful (we also need it!). But we want to delete resources not created with Terraform, so awsweeper is just what we need.

jckuester commented 4 years ago

You mean by this that ECS can't be deleted with the current implementation of awsweeper?

You can try, but I guess the answer is no. I will renew the deletion part in the next weeks by using what I learned from terradozer. Hope you can wait a bit. Sorry for the inconvience.

jckuester commented 4 years ago

@siran prepare the PR as much as you can, I will take care of it asap

UPDATE: I have started integrating the new destroy API (see https://github.com/cloudetc/awsweeper/pull/67), which means deleting ECS resources will soon work.

jckuester commented 4 years ago

@siran I am done with making some bigger changes to potentially support deleting now any AWS resource with awsweeper (https://github.com/cloudetc/awsweeper/pull/67 is merged to master). You can go ahead and test your changes now. Let me know if you need any help.

jckuester commented 4 years ago

@siran I merged your PR locally and finished support for aws_ecs_cluster resource in https://github.com/cloudetc/awsweeper/pull/84.

Note that aws_ecs_cluster resources can only be deleted if all of the following dependencies are gone:

aws_ecs_task_definition
aws_ecs_service
aws_ecs_capacity_provider

So let me know, then I can support those resource types, too.