ec2-subnet, security-group and internet-gateway skip all resources when one is deleted during the scan

Open Beginner friendly
#1,208 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

@toabctl is already working on this.

Since Dec 3, 2026.

  • #1209 by @toabctl — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
aws, go
Domain
backend, cloud

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.

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gruntwork-io/cloud-nuke

All issues in gruntwork-io/cloud-nuke

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.