ec2-subnet, security-group and internet-gateway skip all resources when one is deleted during the scan
Maintainers usually reply within 5 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start with the first-seen handling in aws/resources/ec2_subnet.go and util/time.go, then compare the error handling in the security-group, internet-gateway, and other listers named in the issue. Check how CreateTags reports a missing resource and how the listers handle it. Done means a deleted resource is skipped while remaining resources are still listed, with resources lacking a first-seen tag left undeleted for that run.
Written by the indexing model from the issue text.
Description
Describe the bug
In v0.53.0, the ec2-subnet lister calls util.GetOrCreateFirstSeen for every subnet without a cloud-nuke-first-seen tag. That function calls CreateTags. When a subnet is deleted between DescribeSubnets and CreateTags, CreateTags fails with InvalidSubnetID.NotFound, and the lister returns nil, err. All subnets of the region are dropped from the run, not only the deleted one. The run still exits successfully.
aws/resources/ec2_subnet.go#L73-L77util/time.go#L100-L124: theCreateTagserror is returned as is
security-group (L98-L102) and internet-gateway (L99-L103) have the same return nil, err. So do ec2-endpoint, ec2-placement-groups, eip and network-firewall-tls-config. Other first-seen listers, such as vpc (L79-L83), route tables, network ACLs and ENIs, log the error and continue.
master (e3ce014) has the same code.
Evidence
cloud-nuke v0.53.0, cloud-nuke aws --older-than 3h every 2 hours, with ec2-subnet, security-group and internet-gateway among the resource types. In this account, CI tests create and delete subnets and security groups all the time.
ERROR unable to retrieve first seen tag
ERROR Unable to retrieve ec2-subnet, ec2-subnet: failed to list resources in us-west-2: operation error EC2: CreateTags, https response error StatusCode: 400, RequestID: <id>, api error InvalidSubnetID.NotFound: The subnet ID 'subnet-<id>' does not exist
The subnet listing failed in 8 of 10 runs. In those runs no subnet was deleted. Security groups failed in some runs with InvalidGroup.NotFound, and internet gateways failed once. Old subnets accumulated until the VPC reached its subnet limit.
Expected behavior
Only the deleted resource is skipped. For example, GetOrCreateFirstSeen or the lister could treat a *.NotFound error from CreateTags as "resource gone" and continue with the next resource. Resources without a first-seen tag would still not be deleted in that run.
- Dominant language
- Go
- Stars
- 3.2k
- Forks
- 381
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gruntwork-io/cloud-nuke
-
NAT gateway wait fails all gateways of a batch on NatGatewayNotFound (regression of #325)Possibly taken @james00012 claimed this 7 days ago. Open
gruntwork-io/cloud-nuke#1205 · 1 assignee ·
Maintainers usually reply within 5 days
All issues in gruntwork-io/cloud-nuke
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
snowflakedb/gosnowflake#1872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Linux 主机 macOS 主机
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Lee-xeo/Claude-Cage#1455 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days