ci: reap the AWS resources leaked by failed Terraform test runs - #38725
Draft
bobbyiliev wants to merge 1 commit into
Draft
ci: reap the AWS resources leaked by failed Terraform test runs#38725bobbyiliev wants to merge 1 commit into
bobbyiliev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scratch-account reaper cleans Kinesis streams, S3 buckets, SQS queues and IAM roles named
testdrive*, plus EC2 instances taggedscratch-delete-after. None of that covers the AWS Terraform tests: their resources are prefixedaws-test-dev/aws-up-dev, and the harness tags themdeleteAfter(which the RequireTagsScratch SCP requires) rather thanscratch-delete-after, so nothing ever read it. A run that dies before its teardown therefore leaks its EKS cluster, VPC, NAT gateway, interface endpoints, addresses and log groups permanently, and since the roots use fixed name prefixes the leaked cluster and log group then fail every later run on "already exists".clean_up_terraform_testssweeps resources carrying the harness'sreasontag whosedeleteAfterhas passed, deleting in dependency order: node groups before their cluster, the log group after it, NAT gateways before the addresses they hold, and the VPC last.The sweep is best effort and never raises. Some of these deletions are order-sensitive in ways one pass cannot always satisfy, and a leftover that the next run collects is much better than a cleanup step that goes red. Expiry is what keeps it safe: the aws-persistent root sets
deleteAfterto 2099 so it is never a candidate, and a temporary run in flight is 24 hours from expiring.Test plan
Exercising this needs an expired leak in the scratch account, which is exactly the state we just cleared by hand, so it is verified by the next leak rather than on demand. The discovery half was validated against the real account before the cleanup: the same
reasontag filter is what identified the two leaked environments, and theirdeleteAftervalues were months in the past.expired_terraform_test_resourcesis separated out from the deletions so the ARN parsing and expiry filtering can be exercised without touching AWS.🤖 Generated with Claude Code