cloud-nuke This Week: Account ID Scope Refactor

It was a quiet but deep week for cloud-nuke, the tool that clears out AWS resources across accounts and regions. One large refactor landed, PR #1203, touching 72 files with 440 insertions and 250 deletions. The change is invisible to CLI users, but it fixes a real correctness gap and prepares the ground for per account accounting.

The account ID now travels with each resource

Before this change, the AWS account ID was pushed into a context value during Prepare in aws/provider.go. Resources read it from the context when they tagged what they had seen. The problem: the nuke phase runs on the caller’s context, not the one Prepare returns, so a value attached there would never reach a nuker. The comment in the new code says this plainly.

The fix stops using context values entirely. The account ID is now passed through GetAndInitRegisteredResources in aws/resource_registry.go and stored on each resource’s Scope, in aws/resources/adapter.go. Both the lister and the nuker receive the Scope, so every phase sees the same account.

A new regression test, TestRegisteredResourcesCarryTheAccountID in aws/provider_test.go, pins that the ID actually lands on the Scope, using S3 Control access points as the check.

What the commit touches

The refactor spreads across many resource files because every resource implementation picks up the new Init signature and Scope field. Examples from the change include:

All of these were touched by the same commit, the account scope refactor. Nothing here changes which resources get scanned or nuked; it changes how the account identity reaches the code that does so. The PR title also mentions counting undated resources, which fits the same theme: once a resource knows its account, reporting what it saw per account gets simpler.

Should you care as a user?

For anyone running cloud-nuke in CI or by hand, the answer is mostly no. There is no flag change, no default flip, and no migration step. If you write custom resource code or submit PRs that add new resource types, the Init signature change is the part that will touch you: your resource now receives the account ID alongside the AWS config, and you should store it on the Scope rather than reading it from context.

What to watch

Two things seem worth tracking:

  • Follow up work on per account reporting. The Scope now carries the account, so expect commits that use it for better tagging of scanned and nuked resources.
  • More PRs from the contributors converting remaining context reads to Scope reads, since the old util.AccountIdKey path is gone from the adapter.

The full history is on the cloud-nuke GitHub repository if you want to read the diff yourself.

← All updates