Skip to content

feat(plan): estimate the full post-apply fleet from plan JSON (#51)#52

Merged
andreacappelletti97 merged 1 commit into
mainfrom
feat/plan-full-fleet
Jul 18, 2026
Merged

feat(plan): estimate the full post-apply fleet from plan JSON (#51)#52
andreacappelletti97 merged 1 commit into
mainfrom
feat/plan-full-fleet

Conversation

@andreacappelletti97

@andreacappelletti97 andreacappelletti97 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Implements the decision from #51.

Decision

c3x estimate <plan.json> now prices the full post-apply fleet (walk planned_values), not just the resources the plan changes — the same meaning as estimating the .tf. This fixes the near-zero total for plans where most resources are unchanged.

What changed

  • Parser walks planned_values (the complete post-apply state); data sources and null child_modules entries are skipped, not dereferenced.
  • Fallback to resource_changes for older plan formats, now keeping no-op resources and excluding delete-only ones (post-apply semantics).
  • Help text notes the plan semantics and that --budget gates the full projected total.

Behavior change (called out for release notes)

estimate <plan.json> and --format json from a plan now report the full total. --budget therefore gates the whole fleet. The change-only view remains available via c3x diff (and the upcoming --show-delta).

Tests

New: unchanged-included, child-module walk with null-guard + data-source skip, fallback keeps-no-op/excludes-delete. Full suite + go vet pass. Verified end-to-end: a plan with a no-op + a create now prices both.

Thanks to @Tyron2k, whose #46 surfaced this; that PR can now rescope to the --show-delta view and optional() defaults on top of this consistent base.

Resolves #51.

estimate <plan.json> previously read only resource_changes and filtered
no-op/delete actions, so a plan where most resources are unchanged
returned a near-zero cost. Walk planned_values (the complete post-apply
state) so every resource that will exist after apply is priced -- the
same meaning as estimating the .tf, and consistent with infracost
breakdown. Plans without planned_values fall back to resource_changes,
keeping unchanged resources and excluding delete-only ones. Null
child_modules entries no longer panic the walk.

Behavior change: estimate <plan.json> (and --format json from a plan)
now reports the full projected total, so --budget gates the whole fleet,
not just the change.

Resolves #51.
@andreacappelletti97
andreacappelletti97 merged commit aec1a20 into main Jul 18, 2026
3 checks passed
@andreacappelletti97
andreacappelletti97 deleted the feat/plan-full-fleet branch July 18, 2026 00:36
andreacappelletti97 added a commit that referenced this pull request Jul 18, 2026
estimate <plan.json> previously read only resource_changes and filtered
no-op/delete actions, so a plan where most resources are unchanged
returned a near-zero cost. Walk planned_values (the complete post-apply
state) so every resource that will exist after apply is priced -- the
same meaning as estimating the .tf. Plans without planned_values fall
back to resource_changes, keeping unchanged resources and excluding
delete-only ones. Null child_modules entries no longer panic the walk.

Behavior change: estimate <plan.json> (and --format json from a plan)
now reports the full projected total, so --budget gates the whole fleet,
not just the change.

Resolves #51.
Tyron2k pushed a commit to Tyron2k/c3x that referenced this pull request Jul 21, 2026
…on safety

Builds on c3xdev#52 (planned_values walk) with three additions:

1. PlanAction annotations: each resource from planned_values is
   annotated with its intent (create/update/no-op) from
   resource_changes via buildActionMap/classifyActions. This enables
   downstream delta rendering without losing completeness.

2. Deleted resources are appended with their pre-apply ("before")
   attributes and PlanActionDelete, so the delta renderer can show
   what is being removed and subtract its cost.

3. provider_config.expressions now uses json.RawMessage + parseExpression()
   instead of a strict struct. Terraform 4.x azurerm emits the features
   block as an array ([{}]) which crashed the previous decoder.

Also adds PlanAction type and constants to domain.Resource.
Tyron2k pushed a commit to Tyron2k/c3x that referenced this pull request Jul 22, 2026
…d view

Deleted resources were appended to the output for the delta renderer
but inadvertently inflated PROJECT TOTAL and appeared in the standard
(non-delta) view — regressing the c3xdev#52 post-apply-fleet semantics.

Fix:
- NewEstimate skips PlanActionDelete costs when summing ProjectTotal.
- Standard renderer skips deleted resources entirely (they only surface
  in --show-delta mode with the `-` marker).
- Action markers (+/~/−) are now scoped to delta mode only; the normal
  estimate view shows no plan-action prefixes.
andreacappelletti97 pushed a commit that referenced this pull request Jul 22, 2026
Adds a plan-aware delta view and resolves optional() type-constraint
defaults, building on the full-fleet plan estimate from #52.

- feat: c3x estimate --show-delta renders a diff-style view from plan
  JSON with +/~/- markers, a DELTA line (creates and updates net of
  deletions), and a rolled-up summary of unchanged resources. Falls back
  to the standard renderer with a stderr warning when there is no plan
  context (for example a plain .tf input).
- feat: resolve optional(type, default) defaults from module variable
  type constraints for both the root and child modules, matching
  Terraform's runtime behavior so catalog expressions see real values
  instead of nil placeholders.
- fix: guard the planned_values walk against a null child_modules element
  and the type-constraint walk against a zero-arg object(); both could
  panic the parser on untrusted plan or HCL input.
- fix: exclude resources scheduled purely for deletion from PROJECT TOTAL
  so the estimate stays the post-apply fleet. Deletions surface only in
  the --show-delta view, where their cost is subtracted in the DELTA line.

Co-authored-by: Tino Pittner <tino.pittner@rackspace.com>
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.

Decide: should estimate <plan.json> price the full post-apply fleet or only changed resources?

1 participant