Skip to content

Commit

Permalink
reaper: Switch to libnuke for aws-nuke
Browse files Browse the repository at this point in the history
libnuke is more actively developed compared to upstream aws-nuke, and
also has support for GCP and Azure, which could be a nice backend for
reaper in the future, all based on libnuke.

A new internal package libnukemod has been added with modifications and
extensions to libnuke to fit with reaper needs. It contains aws.go for
all the aws-nuke related helpers. This can be further extended in the
future to add GCP and Azure helpers.

Signed-off-by: Sunny <github@darkowlzz.space>
  • Loading branch information
darkowlzz committed Jun 28, 2024
1 parent b5135a6 commit aa4fb44
Show file tree
Hide file tree
Showing 15 changed files with 1,321 additions and 779 deletions.
11 changes: 8 additions & 3 deletions tools/reaper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ account with the following permissions to delete integration test resources:
- `artifactregistry.repositories.get`
- `artifactregistry.repositories.delete`

For aws-nuke, a new deleter IAM policy can be created and assigned to the reaper
IAM principal with the following policy document:
For [aws-nuke][aws-nuke], a new deleter IAM policy
can be created and assigned to the reaper IAM principal with the following
policy document:

```json
{
Expand All @@ -50,6 +51,7 @@ IAM principal with the following policy document:
"ec2:DescribeInstances",
"ec2:DescribeLaunchTemplates",
"ec2:DescribeNatGateways",
"ec2:DescribeRegions",
"ec2:DescribeSecurityGroups",
"ec2:DescribeInternetGateways",
"ec2:DescribeNetworkInterfaces",
Expand All @@ -67,6 +69,7 @@ IAM principal with the following policy document:
"ec2:DeleteSubnet",
"ec2:DeleteRouteTable",
"ec2:DeleteVolume",
"ec2:DeleteTags",
"ec2:DeleteInternetGateway",
"ec2:DetachInternetGateway",
"ec2:RevokeSecurityGroupEgress",
Expand Down Expand Up @@ -137,9 +140,11 @@ The above command would list the resources that are older than 3 days.

In order to delete these resources, pass the `-delete` flag.

**NOTE:** For AWS, unlike the other providers, a third party tool, `aws-nuke`,
**NOTE:** For AWS, unlike the other providers, a third party tool, [aws-nuke][aws-nuke],
is used. The `aws` provider may be removed in the future. It works in a very
limited manner using the Resource Groups Tagging API. The replacement,
`aws-nuke` provider, is capable of listing and deleting the resources properly.

Use the `-h` flag to list all the available options.

[aws-nuke]: https://github.com/ekristen/aws-nuke
218 changes: 0 additions & 218 deletions tools/reaper/aws-nuke.go

This file was deleted.

29 changes: 13 additions & 16 deletions tools/reaper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ go 1.22

replace github.com/fluxcd/test-infra/tftestenv => ../../tftestenv

// Refer https://github.com/rebuy-de/aws-nuke/issues/955. Use Optum's forked
// patch for now.
replace github.com/rebuy-de/aws-nuke/v2 => github.com/Optum/aws-nuke/v2 v2.25.1

require (
github.com/aws/aws-sdk-go v1.50.6
github.com/aws/aws-sdk-go v1.53.19
github.com/ekristen/aws-nuke/v3 v3.2.2
github.com/ekristen/libnuke v0.17.1
github.com/fluxcd/test-infra/tftestenv v0.0.0
github.com/k1LoW/duration v1.2.0
github.com/onsi/gomega v1.18.1
github.com/rebuy-de/aws-nuke/v2 v2.25.0
github.com/sirupsen/logrus v1.9.3
)

Expand All @@ -29,7 +26,7 @@ require (
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand All @@ -40,6 +37,7 @@ require (
github.com/google/go-containerregistry v0.11.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gotidy/ptr v1.4.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -48,7 +46,6 @@ require (
github.com/hashicorp/terraform-exec v0.18.1 // indirect
github.com/hashicorp/terraform-json v0.15.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -64,18 +61,18 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stevenle/topsort v0.2.0 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
github.com/zclconf/go-cty v1.13.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
Expand Down
Loading

0 comments on commit aa4fb44

Please sign in to comment.