Repository navigation
Conversation
A state document has a top-level `values` where a plan has `planned_values`, so passing one to the plan parser returned zero resources and no error. Add ParseState, which reads `values` with the existing module walker and applies the usual inheritance and region enrichment, and reject a plan passed by mistake instead of silently returning nothing. State records the real identifiers (a bucket's name) that expressions in configuration often cannot resolve; `c3x usage sync` (c3xdev#97, design in c3xdev#99) needs them to map a Terraform address to a cloud resource. Nothing calls ParseState yet.
andreacappelletti97
left a comment
There was a problem hiding this comment.
Thanks for this, and for splitting the work into three reviewable pieces. The approach is right: reusing collectPlanned for values, the same enrichment as Parse, and rejecting a plan instead of returning nothing. I ran the full suite on your branch and it passes.
Two things I'd like fixed here, since usage sync will sit on top of this:
-
A raw
terraform.tfstatereturns zero resources and no error. Passing the state file itself rather thanterraform show -jsonoutput is an easy mistake, and it hits the same silent failure this PR removes for plans. A raw state has a top-levelversionandresourcesand novalues; couldParseStateBytesreject it with an error that says to runterraform show -json? -
Deposed objects are returned alongside the current one. While a
create_before_destroyreplacement is in progress, state lists the old object with adeposed_keyunder the same address as the new one. Both come back today, so one address would map to two cloud resources. Skipping entries with adeposed_keyin the state path (a field onplannedResourcewould do it) keeps one resource per address.
A test for each would be great. Everything else looks good to me.
First of three small PRs for ROADMAP K.1 (
c3x usage sync, #97, design in #99). Split so each can be reviewed alone: this one, then the synced-usage-file loading, thenusage syncitself with S3 storage.What
terraform show -jsonon a state has a top-levelvalueswhere a plan hasplanned_values. Passing a state to the plan parser today returns zero resources and no error.plan.ParseStateFile/ParseStateBytesreadvalueswith the existingcollectPlannedmodule walker (same shape asplanned_values).parser.ParseStatewraps it with the usualapplyInheritance/applyResourceRegions, likePlanBaselineandParsePostApply.Why
Design §4 makes state the source of truth for mapping
aws_s3_bucket.datato the real bucket name, andvalues.regiongives the region the provider reported.Ref.Label()of a state resource equals the stateaddress, which is also theresource_usagekey.Nothing calls
ParseStateyet, so there is no behaviour change.Tests
go test -race ./internal/parser/...: module and indexed addresses, data sources skipped, region fromvalues.region, empty state, plan rejected, invalid JSON, missing file.