Skip to content

Commit

Permalink
Add script to clean up orphaned AWS resources (hashicorp#994)
Browse files Browse the repository at this point in the history
* Add script to clean up orphaned AWS resources

Usage: `cd hack/aws-acceptane-test-cleanup && go run main.go`

This script deletes EKS clusters and VPCs with the name consul-k8s-*
and tagged with build_url. It can be used to clean up resources orphaned
from failed acceptance test runs.

In the future we may want to run this in CI.

* Remove unnecessary hasTags func
  • Loading branch information
lkysow authored Jul 12, 2021
1 parent 9598a35 commit 83b32de
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 4 deletions.
37 changes: 33 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,29 @@ jobs:
gcloud container clusters delete $cluster --zone us-central1-a --project ${CLOUDSDK_CORE_PROJECT} --quiet
done
cleanup-eks-resources:
docker:
- image: docker.mirror.hashicorp.services/hashicorpdev/consul-helm-test:0.9.0
steps:
- checkout

- run:
name: configure aws
command: |
aws configure --profile helm_user set aws_access_key_id "$AWS_ACCESS_KEY_ID"
aws configure --profile helm_user set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
aws configure set role_arn "$AWS_ROLE_ARN"
aws configure set source_profile helm_user
echo "unset AWS_ACCESS_KEY_ID" >> $BASH_ENV
echo "unset AWS_SECRET_ACCESS_KEY" >> $BASH_ENV
- run:
name: cleanup eks resources
command: |
cd hack/aws-acceptance-test-cleanup
go run ./... -auto-approve
workflows:
version: 2
test:
Expand Down Expand Up @@ -694,17 +717,23 @@ workflows:
jobs:
- cleanup-gcp-resources
- cleanup-azure-resources
# - acceptance-openshift: <-- Disabled until we can make them less flakey.
# requires:
# - cleanup-azure-resources
- cleanup-eks-resources
- acceptance-openshift:
requires:
- cleanup-azure-resources
- acceptance-gke-1-17:
requires:
- cleanup-gcp-resources
- acceptance-eks-1-18
- acceptance-eks-1-18:
requires:
- cleanup-eks-resources
- acceptance-aks-1-19:
requires:
- cleanup-azure-resources
- acceptance-kind-1-21
# - acceptance-openshift: <-- Disabled until we can make them less flakey.
# requires:
# - cleanup-azure-resources
update-helm-charts-index:
jobs:
- update-helm-charts-index:
Expand Down
9 changes: 9 additions & 0 deletions hack/aws-acceptance-test-cleanup/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/hashicorp/consul-helm/hack/aws-acceptance-test-cleanup

go 1.16

require (
github.com/aws/aws-sdk-go v1.38.63
github.com/cenkalti/backoff/v4 v4.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
)
28 changes: 28 additions & 0 deletions hack/aws-acceptance-test-cleanup/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
github.com/aws/aws-sdk-go v1.38.63 h1:BqPxe0sujTRTbir6OWj0f1VmeJcAIv7ZhTCAhaU1zmE=
github.com/aws/aws-sdk-go v1.38.63/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ=
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Loading

0 comments on commit 83b32de

Please sign in to comment.