checkov icon indicating copy to clipboard operation
checkov copied to clipboard

fix(terraform): Fix possible exception when for_each data has boolean values

Open alanszlosek opened this issue 5 months ago • 0 comments

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Fixes #6731.

When for_each is used over data with boolean values, an exception can occur. See tests in this PR for what relevant Terraform might look like.

This fix prevents the logic from looking at an attribute's value for additional string interpolation expressions to process when it doesn't need to. Example: If we already processed monitoring="${each.value.monitoring_boolean}", we don't need to check the value of instance_type again for more interpolation expressions.

Checklist:

  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] I have added tests that prove my feature, policy, or fix is effective and works
  • [x] New and existing tests pass locally with my changes

Generated description

Dear maintainer, below is a concise technical summary of the changes proposed in this PR:

Fix an exception in ForeachAbstractHandler when processing boolean values in Terraform for_each data. Modify the logic to avoid unnecessary checks for string interpolation expressions. Update test resources to include boolean monitoring attributes, ensuring the fix is effective.

TopicDetails
Test Updates Add tests for boolean monitoring attributes in Terraform resources to validate the fix.
Modified files (3)
  • tests/terraform/graph/variable_rendering/test_resources/dynamic_blocks_tfvars_merge/terraform.tfvars
  • tests/terraform/graph/variable_rendering/test_resources/dynamic_blocks_tfvars_merge/main.tf
  • tests/terraform/graph/variable_rendering/test_resources/dynamic_blocks_tfvars_merge/variables.tf
Latest Contributors(1)
EmailCommitDate
62605534+SteveVaknin@u...fix-terraform-Fix-fore...September 08, 2024
Boolean Handling Fix an exception in ForeachAbstractHandler when processing boolean values in Terraform for_each data.
Modified files (1)
  • checkov/terraform/graph_builder/foreach/abstract_handler.py
Latest Contributors(2)
EmailCommitDate
62605534+SteveVaknin@u...fix-terraform-Fix-fore...September 08, 2024
[email protected]...fix-terraform-Correctl...February 04, 2024
This pull request is reviewed by Baz. Join @alanszlosek and the rest of your team on (Baz).

alanszlosek avatar Sep 25 '24 17:09 alanszlosek