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): fix external modules ids in graph report #3584

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions checkov/terraform/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ def get_graph_checks_report(self, root_folder: str, runner_filter: RunnerFilter)
connected_node_data = self.get_connected_node(entity, root_folder)
if platform.system() == "Windows":
root_folder = os.path.split(full_file_path)[0]
resource_id = ".".join(entity_context['definition_path'])
resource = resource_id
module_dependency = entity.get("module_dependency_")
module_dependency_num = entity.get("module_dependency_num_")
if module_dependency and module_dependency_num:
referrer_id = self._find_id_for_referrer(f'{full_file_path}[{module_dependency}#{module_dependency_num}]')
if referrer_id:
resource = f'{referrer_id}.{resource_id}'
record = Record(
check_id=check.id,
bc_check_id=check.bc_id,
Expand All @@ -224,7 +232,7 @@ def get_graph_checks_report(self, root_folder: str, runner_filter: RunnerFilter)
file_path=f"/{os.path.relpath(full_file_path, root_folder)}",
file_line_range=[entity_context.get('start_line'),
entity_context.get('end_line')],
resource=".".join(entity_context['definition_path']),
resource=resource,
entity_tags=entity.get('tags', {}),
evaluations=entity_evaluations,
check_class=check.__class__.__module__,
Expand All @@ -236,7 +244,7 @@ def get_graph_checks_report(self, root_folder: str, runner_filter: RunnerFilter)
connected_node=connected_node_data
)
if self.breadcrumbs:
breadcrumb = self.breadcrumbs.get(record.file_path, {}).get(record.resource)
breadcrumb = self.breadcrumbs.get(record.file_path, {}).get(resource_id)
if breadcrumb:
record = GraphRecord(record, breadcrumb)
record.set_guideline(check.guideline)
Expand Down
1 change: 1 addition & 0 deletions tests/terraform/graph/runner/test_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ def test_module_and_variables(self):
bc = bc[0]
self.assertEqual(bc.get('type'), 'module')
self.assertEqual(os.path.relpath(bc.get('path'), resources_path), 'examples/complete/main.tf')
self.assertEqual(record.resource, 'module.s3_bucket.aws_s3_bucket.default')

self.assertTrue(found_versioning_failure)