Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terraform): Skip evaluating each.value expressions in try functions #6766

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rotemavni
Copy link
Collaborator

@rotemavni rotemavni commented Oct 12, 2024

User description

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

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

New/Edited policies (Delete if not relevant)

Description

Include a description of what makes it a violation and any relevant external links.

Fix

How does someone fix the issue in code and/or in runtime?

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • 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:

Enhance the terraform_try function to handle exceptions when evaluating expressions like 'each.value' and 'locals.x'. Introduce a mechanism to skip these evaluations without crashing by returning the first argument that does not produce an error. Modify the evaluate function to replace 'each.value' with a placeholder exception to prevent evaluation errors. Add new test cases in test_string_evaluation.py and test_ALBListenerHTTPS.py to verify the correct handling of 'try' expressions and ensure the robustness of the changes.

TopicDetails
Exception Handling Improve the terraform_try function to handle exceptions gracefully when evaluating expressions like 'each.value' and 'locals.x'.
Modified files (1)
  • checkov/terraform/graph_builder/variable_rendering/safe_eval_functions.py
Latest Contributors(2)
EmailCommitDate
49649760+lirshindalman...fix-terraform-evaluate...August 12, 2024
[email protected]...fix-terraform-Fixed-bu...March 21, 2024
Test Configurations Update Terraform test configurations to include scenarios with 'try' expressions, ensuring comprehensive test coverage.
Modified files (1)
  • tests/terraform/checks/resource/aws/example_ALBListenerHTTPS/main.tf
Latest Contributors(0)
EmailCommitDate
Testing Enhancements Add test cases to verify the correct handling of 'try' expressions in Terraform configurations, ensuring the robustness of the changes.
Modified files (2)
  • tests/terraform/checks/resource/aws/test_ALBListenerHTTPS.py
  • tests/terraform/graph/variable_rendering/test_string_evaluation.py
Latest Contributors(2)
EmailCommitDate
62605534+SteveVaknin@u...fix-terraform-Fix-cond...April 10, 2024
[email protected]...fix-terraform-Fixed-bu...March 21, 2024
This pull request is reviewed by Baz. Join @rotemavni and the rest of your team on (Baz).

@rotemavni rotemavni changed the title fix(terraform) Skip evaluating each.value expressions in try functions fix(terraform): Skip evaluating each.value expressions in try functions Oct 12, 2024
@rotemavni rotemavni marked this pull request as ready for review October 13, 2024 06:08
Copy link
Contributor

@bo156 bo156 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my questrion on the exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants