fix(toolkit-lib): drift numResourcesUnchecked ignores UNKNOWN-status resources - #1837
Open
Adityaj0 wants to merge 1 commit into
Open
Conversation
…resources DriftFormatter.formatStackDrift() computed numResourcesUnchecked as `allStackResources.size - resourceDriftResults.length` - only counting resources CloudFormation returned no drift record for at all. The actual "Unchecked Resources" text section (formatStackDriftChanges) also treats a resource with an UNKNOWN-status drift record as unchecked, which is a real, common status (missing permissions, unsupported resource type, throttling). This meant a resource could be printed under "Unchecked Resources" while numResourcesUnchecked - and therefore the CLI's final summary line, which sums this field and only appends "(N unchecked)" when it's truthy - showed 0, silently dropping the warning and contradicting the detailed output. Extracts the unchecked-resource computation into a single getUncheckedResources() helper used by both the numeric count and the printed list, so they can't diverge again. Fixes aws#1836
aws-cdk-automation
enabled auto-merge
August 14, 2026 21:37
Adityaj0
requested a deployment
to
integ-approval
August 14, 2026 21:37 — with
GitHub Actions
Waiting
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.
fixes #1836
Reason for this change
`DriftFormatter.formatStackDrift()` (`packages/@aws-cdk/toolkit-lib/lib/api/drift/drift-formatter.ts`) computed:
This only counts resources CloudFormation returned no drift record for at all. But the printed "Unchecked Resources" text section (`formatStackDriftChanges`, a few lines below) uses different, more complete logic — it also treats a resource as unchecked if it has a drift record whose status is `UNKNOWN`:
`UNKNOWN` is a real, common CloudFormation status (missing permissions, resource type without full drift-detection support, throttling — there's already error-handling elsewhere in this codebase specifically for it).
Net effect: a resource with an `UNKNOWN`-status drift record is listed under "Unchecked Resources" in the detailed output, but doesn't count toward `numResourcesUnchecked`. That field feeds `Toolkit.driftAll`'s final summary line in `toolkit.ts`:
...so if the only unchecked resources have `UNKNOWN` status (rather than being entirely missing from the results), `totalUnchecked` is 0 and the `(N unchecked)` suffix is silently dropped — even though the detailed output right above it explicitly lists an unchecked resource. Self-contradictory CLI output that can give false confidence everything was verified.
Description of changes
Extracts the unchecked-resource computation into a single `getUncheckedResources()` private helper, used by both:
so the count and the list are computed from one source of truth and can't diverge again.
Description of how you validated changes
Added assertions to the two existing tests that already construct `UNKNOWN`-status fixtures (`'formatting with UNKNOWN drift status'` and `'formatting with only UNKNOWN drift status'` in `test/api/drift/drift.test.ts`) — they exercised the `unchecked` text output but never checked `numResourcesUnchecked`. Verified both new assertions fail on the pre-fix code (expected 1 / 2, got 0 in both cases) and pass with the fix.
Ran the full `test/api/drift/` and `test/actions/drift.test.ts` suites — 27 passed, no regressions. `eslint --fix` clean.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license