Skip to content

feat: add CloudFormation resource count warning - #214

Open
hoegertn wants to merge 7 commits into
mainfrom
feat/resource-count-warning
Open

hoegertn wants to merge 7 commits into
mainfrom
feat/resource-count-warning

Conversation

@hoegertn

@hoegertn hoegertn commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

Reimplements #158 with improvements based on the feedback from the previous attempt in PR #172.

This PR adds a CloudFormation resource counting feature that monitors resource usage across stacks during CDK synthesis and warns when approaching the 500 resource limit.

Changes

New Files

  • src/awscdk/count-resources.ts — Standalone CLI tool that parses the cloud assembly's manifest.json, counts resources per stack, and outputs results to console, JSON file, and optionally GitHub step summary
  • src/awscdk/resource-count-step.ts — ResourceCountStep pipeline step wrapping the CLI call
  • test/count-resources.test.ts — Unit tests for the resource counter logic
  • test/resource-count-github.test.ts — Integration tests for GitHub pipeline
  • test/resource-count-gitlab.test.ts — Integration tests for GitLab pipeline

Modified Files

  • src/awscdk/base.ts — Adds configuration options and provideResourceCountStep() to base class
  • src/awscdk/github.ts — Integrates resource counting into existing synth job with PR comment support
  • src/awscdk/gitlab.ts — Integrates resource counting into existing synth job with MR comment support
  • src/awscdk/index.ts — Exports new module
  • .projenrc.ts — Adds count-resources bin entry

Configuration

new GithubCDKPipeline(this, {
  enableResourceCounting: true,        // default: true
  resourceCountWarningThreshold: 450,  // default: 450
  resourceCountLimit: 500,             // default: 500 (configurable for accounts with increased limits)
});

Improvements over PR #172

  1. No redundant synth — Resource counting runs in the existing synth job rather than a separate workflow
  2. Delta tracking — On PRs, checks out the baseline from the target branch and reports resource count changes
  3. Configurable hard limit — resourceCountLimit option (default 500) for accounts with increased quotas
  4. GitLab MR support — Posts resource count summaries to GitLab merge requests via Notes API
  5. Robust CI behavior — Uses || true so the step does not fail the pipeline; results are always reported

Test Results

  • 17 unit tests for ResourceCounter CLI logic
  • 3 GitHub integration tests (enabled/disabled/custom limits)
  • 2 GitLab integration tests (enabled/disabled)
  • All tests pass

Closes #158

Implements resource counting integrated into the existing synth job:
- count-resources CLI tool parses cloud assembly and counts resources per stack
- ResourceCountStep wraps the CLI as a pipeline step
- GitHub: adds pull_request trigger to deploy workflow, posts PR comment with
  resource counts and deltas vs target branch, skips deploy jobs on PRs
- GitLab: adds resource counting to synth job with conditional MR comment
- Configurable: enableResourceCounting (default true), resourceCountWarningThreshold
  (default 450), resourceCountLimit (default 500)

Closes #158
- Fix continueOnError rendering in baseline checkout step (was using
  kebab-case key that projen's renderer ignores, now uses camelCase)
- Append || true to count-resources CLI invocation so the step does not
  block PR comment posting when resources exceed the limit
- Replace GITLAB_TOKEN with CI_JOB_TOKEN fallback (MR_TOKEN uses
  GITLAB_TOKEN if set, otherwise CI_JOB_TOKEN) and document requirement
- Add TODO comment noting GitLab delta tracking could be added later
- Add comprehensive unit tests for ResourceCounter class (17 tests
  covering boundary conditions, missing manifests, mixed stacks, etc.)
@github-actions
github-actions Bot requested a review from Lock128 August 9, 2026 11:52
Comment thread src/awscdk/github.ts
Comment thread src/awscdk/github.ts Outdated
},
...githubSteps.flatMap(s => s.steps),
{
name: 'Download baseline resource counts',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiro-agent Where does this file come from in the repo. Where is it committed? It should not be stored

kiro-agent and others added 3 commits August 9, 2026 12:53
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.

Enhance the CDK synth with a warning if you are approaching the resource limit.

2 participants