[Terraform plan] tfplan parser losing track of resources#196
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits intoJul 1, 2026
Merged
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: f1c70d9 | Docs | Datadog PR Page | Give us feedback! |
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 18, 2026 12:30
eb783a6 to
3950501
Compare
5 tasks
ChouraquiBen
marked this pull request as ready for review
June 18, 2026 14:40
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3950501f4a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 22, 2026 09:53
3950501 to
ba1d3e1
Compare
ChouraquiBen
changed the base branch from
graphite-base/196
to
benjamin.chouraqui/enable-gated-tfplan-scanning
June 22, 2026 09:53
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5 tasks
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 22, 2026 10:34
ba1d3e1 to
63b02f2
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/enable-gated-tfplan-scanning
branch
from
June 22, 2026 10:34
686a485 to
254bbd2
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 25, 2026 09:10
63b02f2 to
648ce2d
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/enable-gated-tfplan-scanning
branch
from
June 25, 2026 10:22
b7799cf to
d23e0c3
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
2 times, most recently
from
June 25, 2026 10:55
6e89b53 to
c4aba08
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/enable-gated-tfplan-scanning
branch
2 times, most recently
from
June 25, 2026 11:05
bb73637 to
004184a
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 25, 2026 11:05
c4aba08 to
4aeb500
Compare
Base automatically changed from
benjamin.chouraqui/enable-gated-tfplan-scanning
to
main
June 25, 2026 11:15
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 26, 2026 13:32
4aeb500 to
1c3e319
Compare
ChouraquiBen
force-pushed
the
benjamin.chouraqui/fix-tfplan-parser
branch
from
June 30, 2026 14:21
1c3e319 to
f1c70d9
Compare
Contributor
Author
|
Test rules failing is actually a good news: the unexpected finding is legit |
NathanGallet-dd
approved these changes
Jul 1, 2026
gh-worker-dd-mergequeue-cf854d
Bot
merged commit Jul 1, 2026
f67c647
into
main
20 of 21 checks passed
gh-worker-dd-mergequeue-cf854d
Bot
deleted the
benjamin.chouraqui/fix-tfplan-parser
branch
July 1, 2026 13:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
PR #194 enables Terraform plan scanning behind the
--x-terraform-planflag, but the tfplan parser has critical bugs that cause resource loss in multi-module plans. These bugs prevent accurate scanning of real-world Terraform plans with modules, count, or for_each.Related: #194
Changes
Bug Fixes
Fixed module resource loss: Resources from child modules were overwriting root module resources of the same type
readModulewas reinitializingkp.Resource[resource.Type]for each module, erasing previous resourcesmodule.networking.subnet)Fixed count/for_each resource loss: Resources using
countorfor_eachwere overwriting each otherresource.Nameused as key, ignoringIndexfieldname[0],name[1]for count andname["prod"],name["dev"]for for_eachformatResourceKeyWithIndexfunction to handle both numeric and string indexesTest Coverage
Added 6 comprehensive test cases in
tfplan_test.go:Author Checklist
QA Instruction
Test the fixes:
go test ./pkg/parser/json/...Verify Rego query compatibility:
Existing Rego queries using
split(resource, ".")[1]patterns continue to work because root module resources maintain simple names without module prefixes.Blast Radius
--x-terraform-planexperimental flag)Additional Notes
Key Implementation Details
Resource key formats:
resource_name(no prefix for backward compatibility)module.path.resource_nameresource_name[0],resource_name[1], etc.resource_name["prod"],resource_name["staging"], etc.module.app.web[0],module.storage.bucket["prod"]Before these fixes:
{ "resource": { "aws_s3_bucket": { "backup": {...} // Only last module's bucket survives } } }After these fixes:
{ "resource": { "aws_s3_bucket": { "main": {...}, // Root module bucket "module.storage.backup": {...} // Child module bucket - both preserved! } } }I submit this contribution under the Apache-2.0 license.