From 74739f4d477a061127c069b27244aa7c676d4bf4 Mon Sep 17 00:00:00 2001 From: naorda Date: Wed, 16 Aug 2023 14:39:55 +0300 Subject: [PATCH] fix(terraform): ensure TFModule is created properly in definition context (#5446) ensure TFModule is created properly in definition context --- checkov/terraform/runner.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/checkov/terraform/runner.py b/checkov/terraform/runner.py index b77bb822a22..25d7364cfc7 100644 --- a/checkov/terraform/runner.py +++ b/checkov/terraform/runner.py @@ -28,7 +28,7 @@ from checkov.common.util.secrets import omit_secret_value_from_checks, omit_secret_value_from_graph_checks from checkov.common.variables.context import EvaluationContext from checkov.runner_filter import RunnerFilter -from checkov.terraform.modules.module_objects import TFDefinitionKey +from checkov.terraform.modules.module_objects import TFDefinitionKey, TFModule from checkov.terraform.checks.data.registry import data_registry from checkov.terraform.checks.module.registry import module_registry from checkov.terraform.checks.provider.registry import provider_registry @@ -301,9 +301,11 @@ def get_graph_checks_report(self, root_folder: str, runner_filter: RunnerFilter, def get_entity_context_and_evaluations(self, entity: dict[str, Any]) -> dict[str, Any] | None: block_type = entity[CustomAttributes.BLOCK_TYPE] - full_file_path = entity[CustomAttributes.FILE_PATH] - - full_file_path = TFDefinitionKey(file_path=entity.get(CustomAttributes.FILE_PATH), tf_source_modules=entity.get(CustomAttributes.SOURCE_MODULE_OBJECT)) + tf_source_module_obj = entity.get(CustomAttributes.SOURCE_MODULE_OBJECT) + if isinstance(tf_source_module_obj, dict): + tf_source_module_obj = TFModule.from_json(tf_source_module_obj) + full_file_path = TFDefinitionKey(file_path=entity.get(CustomAttributes.FILE_PATH), + tf_source_modules=tf_source_module_obj) definition_path = entity[CustomAttributes.BLOCK_NAME].split('.') entity_context_path = [block_type] + definition_path