diff --git a/checkov/terraform/graph_builder/variable_rendering/safe_eval_functions.py b/checkov/terraform/graph_builder/variable_rendering/safe_eval_functions.py index 174f03ca00..5d66ec0624 100644 --- a/checkov/terraform/graph_builder/variable_rendering/safe_eval_functions.py +++ b/checkov/terraform/graph_builder/variable_rendering/safe_eval_functions.py @@ -2,6 +2,7 @@ import itertools import logging +import os import re from datetime import datetime, timedelta from functools import reduce @@ -380,11 +381,13 @@ def evaluate(input_str: str) -> Any: # Don't use str.replace to make sure we replace just the first occurrence input_str = f"{TRY_STR_REPLACEMENT}{input_str[3:]}" asteval = get_asteval() + log_level = os.getenv("LOG_LEVEL") + should_log_asteval_errors = log_level == "DEBUG" if RANGE_PATTERN.match(input_str): - temp_eval = asteval(input_str) + temp_eval = asteval(input_str, show_errors=should_log_asteval_errors) evaluated = input_str if temp_eval < 0 else temp_eval else: - evaluated = asteval(input_str) + evaluated = asteval(input_str, show_errors=should_log_asteval_errors) if asteval.error: error_messages = [err.get_error() for err in asteval.error]