terraform-aws-consul-ecs icon indicating copy to clipboard operation
terraform-aws-consul-ecs copied to clipboard

Cleanup code for AWS

Open pglass opened this issue 3 years ago • 1 comments

Changes proposed in this PR:

Code we can use to cleanup resources in AWS.

Resources are filtered in a few ways (where possible):

  • Resources whose name contains consul-ecs

  • Resources that contain a build_url tag matching our CircleCI build url https://circleci.com/gh/hashicorp/terraform-aws-consul-ecs/

  • Resources that contain a build_time tag that is old enough

    • There's a new build_time tag added in acceptance test jobs, since some AWS resources do not have created times (like ECS Clusters). And this gives us a consistent way to determine resource age.

How I've tested this PR:

  • Manually setup some resources with the new tags, and ran locally:
$ go run .
2021/10/27 09:57:19 Listing elastic ips
2021/10/27 09:57:19 Listing NAT gateways
2021/10/27 09:57:19 Listing VPCs
2021/10/27 09:57:19 Listing EC2 instances
2021/10/27 09:57:19 Listing ECS clusters
2021/10/27 09:57:19 Listing internet gateways in VPC vpc-0fed33a2425cdf821
2021/10/27 09:57:19 Listing ECS services for cluster=arn:aws:ecs:us-west-2:977604411308:cluster/consul-ecs-et3aRCLL
2021/10/27 09:57:19 Listing subnets for VPC vpc-0fed33a2425cdf821
2021/10/27 09:57:20 Listing security groups for VPC vpc-0fed33a2425cdf821
2021/10/27 09:57:20 Listing route tables for VPC vpc-0fed33a2425cdf821
2021/10/27 09:57:21 main.NatGateway nat-02886e7d998623b64
2021/10/27 09:57:21 main.ElasticIP eipalloc-0cfb382f48b43caf9
2021/10/27 09:57:21 main.EC2Instances [i-058c50ec1c3febd5b i-0b0a9939ed7e06538 i-0f22630f90b050dc5 i-0541da8287312974c]
2021/10/27 09:57:21 main.ECSCluster arn=arn:aws:ecs:us-west-2:977604411308:cluster/consul-ecs-et3aRCLL services=[arn:aws:ecs:us-west-2:977604411308:service/consul-ecs-et3aRCLL/test_server_et3aRCLL arn:aws:ecs:us-west-2:977604411308:service/consul-ecs-et3aRCLL/consul_server_et3aRCLL arn:aws:ecs:us-west-2:977604411308:service/consul-ecs-et3aRCLL/test_client_et3aRCLL]
2021/10/27 09:57:21 main.LogGroup consul-ecs-et3aRCLL
2021/10/27 09:57:21 main.VPC vpc=vpc-0fed33a2425cdf821 igw=igw-0caee38e2da9ecbe5 subnets=[subnet-01e8725681fdd3712 subnet-08e71beda10c92b04 subnet-0be65123220cde755 subnet-0472f94cd0b65cdd6 subnet-0e11625445483060b subnet-079f2f6f86c6787cf] secgroups=[sg-021d3781a2c28ad33] routetables=[rtb-000defd2aba08fcc5 rtb-0102fc731fd9ce60f]

How I expect reviewers to test this PR:

Checklist:

  • [ ] Implement Delete/Wait logic

  • [ ] Tests added

  • [ ] CHANGELOG entry added

pglass avatar Oct 27 '21 15:10 pglass