Repository: bridgecrewio/checkov

Issue:
Encounter `KeyError: 'aws'` error with latest checkov version (2.0.163)
**Describe the bug**
We are encoutering a `KeyError: 'aws'` with the latest version of checkov - 2.0.163 in our CI systems. The source file is `checkov/terraform/context_parsers/base_parser.py` which had recent changes. Please find below the relevant output showcasing the error.

**To Reproduce**
Steps to reproduce the behavior:
1. Install the latest version of checkov via `pip install checkov`
2. Run checkov on a repo - `checkov .`
3. See resulting output with traceback which includes the following error: `KeyError: 'aws'`

**Expected behavior**
We expect checkov to run smoothly and not error out.

**Screenshots**
Below is the command we use with the traceback output:

```sh
[Container] 2021/05/25 17:59:30 Running command checkov -d ./services --quiet --skip-check CKV_AWS_59,CKV_AWS_107,CKV_AWS_108,CKV_AWS_109,CKV_AWS_111,CKV_AWS_120,CKV_AWS_136,CKV_DOCKER_2,CKV_DOCKER_3,CKV_DOCKER_7
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.8.8/bin/checkov", line 8, in <module>
    exit(run())
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/main.py", line 112, in run
    scan_reports = runner_registry.run(root_folder=root_folder, external_checks_dir=external_checks_dir,
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/common/runners/runner_registry.py", line 34, in run
    scan_report = runner.run(root_folder, external_checks_dir=external_checks_dir, files=files,
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/terraform/runner.py", line 106, in run
    self.check_tf_definition(report, root_folder, runner_filter, collect_skip_comments)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/terraform/runner.py", line 184, in check_tf_definition
    definitions_context = parser_registry.enrich_definitions_context(definition, collect_skip_comments)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/terraform/context_parsers/registry.py", line 35, in enrich_definitions_context
    self.definitions_context[tf_file][definition_type] = context_parser.run(
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/terraform/context_parsers/base_parser.py", line 148, in run
    self.context = self._collect_skip_comments(definition_blocks)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/checkov/terraform/context_parsers/base_parser.py", line 105, in _collect_skip_comments
    entity_context = entity_context[k]
KeyError: 'aws'
```

**Desktop (please complete the following information):**
 - OS: MacOS, Linux
 - Checkov Version: 2.0.163

**Additional context**
Add any other context about the problem here (e.g. code snippets).



Discussion:

Resolving patch:
diff --git a/checkov/terraform/context_parsers/base_parser.py b/checkov/terraform/context_parsers/base_parser.py
--- a/checkov/terraform/context_parsers/base_parser.py
+++ b/checkov/terraform/context_parsers/base_parser.py
@@ -101,8 +101,16 @@ def _collect_skip_comments(self, definition_blocks: List[Dict[str, Any]]) -> Dic
             skipped_checks = []
             entity_context_path = self.get_entity_context_path(entity_block)
             entity_context = self.context
+            found = True
             for k in entity_context_path:
-                entity_context = entity_context[k]
+                if k in entity_context:
+                    entity_context = entity_context[k]
+                else:
+                    logging.warning(f'Failed to find context for {".".join(entity_context_path)}')
+                    found = False
+                    break
+            if not found:
+                continue
             for (skip_check_line_num, skip_check) in comments:
                 if entity_context["start_line"] < skip_check_line_num < entity_context["end_line"]:
                     if bc_id_mapping and skip_check["id"] in bc_id_mapping:
diff --git a/checkov/terraform/runner.py b/checkov/terraform/runner.py
--- a/checkov/terraform/runner.py
+++ b/checkov/terraform/runner.py
@@ -170,7 +170,11 @@ def get_entity_context_and_evaluations(self, entity):
                 dc_key = next(x for x in dc_keys if x.startswith(full_file_path))
                 entity_context = self.definitions_context.get(dc_key, {})
             for k in entity_context_path:
-                entity_context = entity_context[k]
+                if k in entity_context:
+                    entity_context = entity_context[k]
+                else:
+                    logging.warning(f'Failed to find context for {".".join(entity_context_path)}')
+                    return None, None
             entity_context['definition_path'] = definition_path
         except StopIteration:
             logging.debug(f"Did not find context for key {full_file_path}")


Test patch: