Skip to content

Cost gate: Infracost threshold logic and usage-file conventions (#91) - #170

Open
ms280690 wants to merge 1 commit into
mainfrom
issue-91-cost-gate
Open

ms280690 wants to merge 1 commit into
mainfrom
issue-91-cost-gate

Conversation

@ms280690

Copy link
Copy Markdown
Collaborator

Closes #91. From main; #89 (the infracost composite's install, breakdown, diff and comment modes plus cost-diff-tofu.yml) stacks on this.

What

  • .github/actions/infracost/gate.py (stdlib): reads totalMonthlyCost, pastTotalMonthlyCost, diffTotalMonthlyCost and summary.totalUsageBasedResources. --max-monthly-increase fails on a positive delta above the USD cap; --max-percent-increase fails when the delta over the base total exceeds the cap (a $0 base with an increase counts as exceeded); both at 0 is comment-only; decreases never fail. Writes the gate line for the PR comment (--snippet) and the step summary, warns when usage-based resources exist and no usage file is given or found, and sets monthly-diff, monthly-total, percent-change, threshold, gate. Exit 1 on a failed gate, 2 on a missing file.
  • docs/cost-gate.md: threshold semantics, recommended values (client infra 200 USD / 10 %, internal 100 USD / 25 %, sandboxes comment-only), exception path through the docs: findings — finding-to-SLA mapping and exception template #81 security-exception form, and the four infracost-usage.yml rules.
  • docs/examples/infracost-usage.yml: starter with commented entries for S3, data transfer, Lambda, DynamoDB on-demand, CloudWatch logs and NAT gateway.
  • CI Cost Gate job running the fixtures.

Tests

tests/infracost/run.sh on sample Infracost JSON (increase, decrease, zero base, no change): comment-only outputs and snippet, USD cap pass and fail, percent cap pass and fail, both caps, decreases with tight caps, zero base under each cap, usage warning present, absent and missing-file, exit codes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NPH9145e4gFo6bmXvMgBoF

gate.py reads Infracost JSON output and fails when the monthly increase
exceeds a USD cap or a percent cap of the base total (both at zero is
comment-only; decreases never fail; a zero base with an increase counts as
exceeded for the percent rule). It writes a one-line gate statement for the
PR comment and step summary, warns when usage-based resources have no
usage file, and sets outputs. docs/cost-gate.md fixes the semantics, the
recommended thresholds per repository class, the exception path and the
infracost-usage.yml rules; docs/examples/infracost-usage.yml is the
starter file. CI runs the gate against sample JSON.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NPH9145e4gFo6bmXvMgBoF
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.

feat: cost — threshold gate and infracost-usage.yml conventions

1 participant