Skip to content

feat(#237): blanket resource pricing via an Infracost breakdown importer - #238

Merged
elecnix merged 1 commit into
mainfrom
feat/237-infracost-breakdown-import
Jul 6, 2026
Merged

feat(#237): blanket resource pricing via an Infracost breakdown importer#238
elecnix merged 1 commit into
mainfrom
feat/237-infracost-breakdown-import

Conversation

@elecnix

@elecnix elecnix commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Closes #237.

What

A generic path to price the static long tail without a hand-written
ResourceType handler + _METRIC_DESCRIPTORS entry per service. Infracost
already encodes extract + cost components + product filters for hundreds of
resources; this ingests its infracost breakdown --format json output and turns
each costed resource into a priced cost-model node.

This makes infra-cost-model a DAG / what-if layer on top of Infracost's pricing
library for the always-on tail — the resources otherwise forced onto hand-written
flatOverride nodes (KMS, WAF, EIP, Route53, …). Native handlers stay for the
request-path resources where the DAG derives usage from upstream flow. Per DP#9,
the import is the escape hatch, not the default: prefer a handler where one
exists.

Changes

  • pricing/sources/infracost_breakdown.pyimport_breakdown(json) -> {address: node}. One flatOverride node per costed resource; costComponents
    and nested subresources flatten into fixed: true metrics valued at each
    component's monthlyCost (namespaced so same-named components don't collide).
    Free resources (no priced components) skipped; provider inferred from the
    resource-type prefix.
  • cli.pyimport-infracost <breakdown.json> (YAML default, --json).
  • tests — importer units (EC2 with an EBS subresource + ElastiCache, engine
    round-trip to the Infracost monthly total) + two CLI tests.
  • README — "Blanket pricing for the long tail".

Design note

Two things block fully automatic blanket support, and this PR is honest about
both: usage derivation isn't recoverable from a resource definition (it's an
input), and AWS usagetype pricing keys aren't mechanically derivable. Infracost
has already solved both for its supported resources, so importing its breakdown
is the highest-leverage way to get breadth. What it can't do — model a resource's
usage as a function of upstream DAG flow — is exactly what the native handlers are
for, so the two compose.

Tests

pytest — full suite green (953 passed); 12 new tests.

Follow-ups (noted in the issue)

  • Reconcile an imported resource that also has a native handler (prefer handler).
  • Optionally wire imported nodes as DAG edges rather than always-on leaves.

Adds a generic path to price the static long tail without a hand-written handler
+ descriptor per service. `import_breakdown` ingests
`infracost breakdown --format json` output and turns each costed resource into a
flatOverride node whose `fixed` metrics mirror Infracost's per-component monthly
costs (subresource components flattened and namespaced; free resources skipped).
Prices through the engine with no catalog lookup.

- pricing/sources/infracost_breakdown.py: import_breakdown + provider inference.
- cli.py: `import-infracost <breakdown.json>` subcommand (YAML/--json output).
- tests: importer unit tests (EC2 + EBS subresource + ElastiCache, engine
  round-trip) and two CLI tests.
- README: "Blanket pricing for the long tail" section.

This is the DP#9 escape hatch for breadth — Infracost covers everything it
prices; native handlers stay for the request-path resources where the DAG
derives usage from upstream flow. Prefer a handler where one exists.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@elecnix
elecnix merged commit c25e7bd into main Jul 6, 2026
3 checks passed
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.

Blanket resource pricing via an Infracost breakdown importer

1 participant