Preserve Terraform data source policies with unknown values#181
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: 38b5f0e | Docs | Datadog PR Page | Give us feedback! |
ChouraquiBen
left a comment
There was a problem hiding this comment.
The code seems to be doing what it means to do to me, but I would like a little bit more context if possible 🙏
Do you know which data resources could not be resolved? Within the test, I am not sure which part is supposed to make the scan fail if the feature is inactive
…fault variables are not dropped.
@ChouraquiBen The affected data source is If you want to try it out: run the new test added in this PR, but without what is added in the scanner in this PR. It will fail because |
43bde21 to
abb0a6f
Compare
Motivation
Terraform
aws_iam_policy_documentdata sources can contain values that are unknown during static analysis. Previously, a single unknown value caused JSON serialization to fail, which dropped the whole policy document from analysis and emitted noisy error logs.Changes
Treat unknown cty values as null before serializing Terraform data source policies, preserving the statically-known portions of the policy instead of dropping the whole document. The remaining serialization failure log is downgraded because routine unknown Terraform values are now handled explicitly.
A regression test covers a policy with an unknown scalar field while preserving known statement fields.
Author Checklist
QA Instruction
go test ./pkg/parser/terraform/... -run Test_getDataSourcePolicy -vBlast Radius
This PR affects Terraform data source policy parsing in the IaC scanner. It only changes handling of unknown values while decoding
aws_iam_policy_documentdata sources.Additional Notes
I submit this contribution under the Apache-2.0 license.