fix(terraform): use resource address in entity path #7338
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.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
All terraform checks that rely on Cloudsplaining use the entity_path, and consequently the resource name, to cache parsed policies. This is a problem when dealing with IAM resources managed in a
for_eachblock.The fix is to use the full resource address to infer the resource name, rather than just it's un-indexed form, so that entity paths will result into something like
...:<resouce_type>.<resrouce_name>[<resource_index>]and the IAM policy caching won't get broken anymore by overlapping keys.I am not sure if
__address__is available in all cases when this code is called, I know for sure it is the case when parsing terraform plan outputs, which is where this issue appears the most, so I made the name extraction conditional on the field being present to avoid breaking other input cases.Fixes #7337
Checklist: