Skip to content

fix(infra): cdk destroy of the Fargate stack works in one run whatever target group is live - #2071

Merged
amarkanday merged 1 commit into
mainfrom
fix/1618-cdk-destroy-one-run
Nov 20, 2026
Merged

amarkanday merged 1 commit into
mainfrom
fix/1618-cdk-destroy-one-run

Conversation

@amarkanday

Copy link
Copy Markdown
Contributor

Resolves #1618

What and why

cdk destroy experimentation-fargate-<env> failed with DELETE_FAILED on a target group "in use by a listener" whenever the last blue/green deployment left the live rules on the other colour. The API path rules (https_listener.add_target_groups) and the TestListener declared no dependency on both target groups, so CloudFormation could delete a group before the rule or listener using it. Both measured staging teardowns hit this once and passed on a retry.

Every API path rule and the TestListener now node.add_dependency on both the blue and the green target group (infrastructure/cdk/stacks/fargate_service_stack.py). docs/self-hosting/cdk.md ("Tearing an environment down") says one run suffices, and that a stack deployed before this change still has the old order (run the teardown again); its claims file pins the sentence to the new test.

Template diff: DependsOn only

The fargate stack was synthesised in-process before and after, for the full and core profiles, each with api_live_target_group blue and green (4 templates, 45 resources each, no cdk CLI, no context lookup). The only difference in every one: three added DependsOn: [BlueTargetGroupF108EB01, GreenTargetGroupEEB2DF3E] lists, on the two API path rules and the TestListener. No Replace, no changed logical id or property.

Verification

  • New regression test infrastructure/tests/test_listeners_depend_on_both_target_groups.py (live blue and green): fails on main's code (...ApiPaths10Rule... depends on [], not on both target groups), passes with the change.
  • Plants: removing the green dependency on the TestListener fails it; removing the blue dependency on the rules fails it.
  • pytest infrastructure/tests -o addopts="" --import-mode=importlib: 1356 passed.
  • scripts/doc_claims.py check: problems: 0; test_docs_only_gate.py: 47 passed; mkdocs build --strict: ok.
  • ruff on the new test: clean. fargate_service_stack.py is outside the lint scope and reports the same three findings on main as with this change.

NOT VERIFIED

No real cdk destroy has run against this: that waits for the next staging teardown. CloudFormation's delete ordering from DependsOn is its documented behaviour, not something these tests exercise.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn

…r target group is live

CodeDeploy swaps which of the blue and green target groups the live
listener rules point at. Neither the API path rules nor the test listener
declared a dependency on both groups, so CloudFormation could delete a
target group before the rule or listener still using it and fail with
"in use by a listener" (#1618). Every API path rule and the test listener
now depend on both target groups.

Only DependsOn entries are added to the synthesised template; no resource,
logical id or property changes. A synth test pins the entries for both
live colours, and docs/self-hosting/cdk.md says one run suffices.

Resolves #1618

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011kqtSDC7sd5ue3m6LuwdXV
Signed-off-by: amarkanday <a.markanday@gmail.com>
@amarkanday
amarkanday merged commit dae7332 into main Nov 20, 2026
62 checks passed
@amarkanday
amarkanday deleted the fix/1618-cdk-destroy-one-run branch November 20, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(infra): cdk destroy of the Fargate stack fails when the last blue/green deploy left green live

1 participant