Repository navigation
setup.sh: bootstrap into CDKToolkit-atxinfra instead of overwriting the shared CDKToolkit - #98
Open
chenxqdu wants to merge 1 commit into
Conversation
…lkit `cdk bootstrap --qualifier atxinfra` without --toolkit-stack-name updates the default CDKToolkit stack in place, which replaces an account's existing hnb659fds bootstrap: its five roles and its SSM version parameter are deleted, and the staging bucket and ECR repository are left orphaned. Every other CDK app in that region then fails to deploy until the default bootstrap is re-created under a different stack name. Bootstrap into CDKToolkit-atxinfra instead -- the stack name teardown.sh already looks for first. Guard the step so existing installs, whose atxinfra resources live inside CDKToolkit, are detected through /cdk-bootstrap/atxinfra/version and skipped (or upgraded in place) rather than re-created under the new stack name, which would fail with AlreadyExists on the roles, the SSM parameter and the ECR repository. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
setup.shbootstraps with a custom qualifier but no toolkit stack name:cdk bootstrapwrites into the default toolkit stack nameCDKToolkitunless--toolkit-stack-nameis passed. In any account that already has a normal CDK bootstrap (qualifierhnb659fds) — i.e. almost every account that has ever runcdk deploy— this updates that shared stack in place and switches its qualifier toatxinfra:/cdk-bootstrap/hnb659fds/versionand the fivecdk-hnb659fds-*roles are deletedcdk-hnb659fds-assets-<account>-<region>andcdk-hnb659fds-container-assets-<account>-<region>survive as orphans, owned by no stack (the template marks the bucketRetain)... has not been bootstrapped/ missing/cdk-bootstrap/hnb659fds/versionRecovery is awkward, because re-running a plain
cdk bootstrapagainst the same stack fails withcdk-hnb659fds-assets-... already exists— the retained bucket blocks the replacement — which leavesCDKToolkitinUPDATE_ROLLBACK_COMPLETEand forces the default bootstrap to be re-created under a different stack name.I hit this on a real account: two regions had their default bootstrap converted to
atxinfra, oneCDKToolkitwas left stuck inUPDATE_ROLLBACK_COMPLETE, ~3.6 GB of staging assets were orphaned, and unrelated stacks could no longer be deployed.teardown.shalready looks for a stack namedCDKToolkit-atxinfrafirst and only falls back toCDKToolkit(checkingQualifier == atxinfra) as a legacy case, so a dedicated toolkit stack looks like the intended layout —setup.shjust never passed the flag.Change
Bootstrap into
CDKToolkit-atxinfraand never touch the sharedCDKToolkit. Since existing installs already have theiratxinfraresources insideCDKToolkit, the step is guarded so it stays idempotent instead of starting to fail:/cdk-bootstrap/atxinfra/version→ bootstrap intoCDKToolkit-atxinfraCDKToolkit-atxinfra, then legacyCDKToolkitwithQualifier == atxinfra); skip when it is v21 or newer, otherwise upgrade that stack in placeCDKToolkit-atxinfraCase 2 is what keeps existing users working: pointing a new stack name at an already-bootstrapped qualifier would fail with
AlreadyExistson the five roles, the SSM parameter and the ECR repository, and the retained staging bucket would end up managed by two stacks.The detection key is the SSM parameter because it is tied to the qualifier rather than to a stack name, so it recognises existing installs no matter which stack name they ended up in.
Testing
bash -n setup.shcdkinvocation stubbed out:atxinfrainsideCDKToolkit→CDK already bootstrapped for qualifier atxinfra (v32 in stack CDKToolkit) — skipping(no hijack, no failure)atxinfrabootstrap →cdk bootstrap aws://<account>/<region> --qualifier atxinfra --toolkit-stack-name CDKToolkit-atxinfraBase branch is
atx-remote-infrarather thanmain, since that is where this sample lives (and where #59 / #61 were merged).Not addressed here
teardown.shdeletes whichever stack holds theatxinfraqualifier, including a legacyCDKToolkit. CloudFormation stacks record theirRoleARNpermanently, so if anything else in the account was deployed throughcdk-atxinfra-cfn-exec-role, deleting that stack leaves those stacks unable to update or delete. That seems worth a similar guard — happy to add it to this PR if you'd prefer it in one change.🤖 Generated with Claude Code