Feat/resolve single depth references #8
Merged
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.
What
Introduce single depth of reference resolution in plan parsing.
Terraform plan cannot resolve all dependencies before apply stage. The unresolved items can still be useful however. We are currently using these references to link resources together in Rego.
Why
Mainly to solve the problem of terraform AWS provider v4.0.0 which introduced breaking changes to s3 bucket.
The reference structure in terraform is actually quite complex. This PR only does basic dereferencing for purposes of allowing us to link resources on first depth attributes. This is good enough to link related S3 resources together.
Review
Given TF plan included in the PR, the parser would produce following output
The produced output does not have any information which allows us to link
aws_s3_bucket_logging.example
toaws_s3_bucket.logging2
.After the change the output looks like this file
You can see that now the
aws_s3_bucket_logging.example
containsbucket
attribute which points toaws_s3_bucket.logging2
Testing
You can build the snyk-iac-rules with this branch. Run following to use this branch in your local build