Handle malformed input case
Fixes: 857
MODIFY
checkov/common/checks/base_check_registry.py
checkov/common/checks/base_check_registry.py
@@ -94,6 +94,10 @@ class BaseCheckRegistry(object):
(entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)
results = {}
+
+ if not isinstance(entity_configuration, dict):
+ return results
+
checks = self.get_checks(entity_type)
for check in checks:
skip_info = {}

MODIFY
checkov/terraform/tag_providers/__init__.py
checkov/terraform/tag_providers/__init__.py
@@ -10,6 +10,9 @@ provider_tag_mapping = {
def get_resource_tags(resource_type, entity_config):
+ if not isinstance(entity_config, dict):
+ return None
+
if '_' not in resource_type:
return None # probably not a resource block
provider = resource_type[:resource_type.index('_')]

ADD
tests/terraform/runner/resources/malformed_857/main.tf
+resource "aws_instance" {
+ ami = "amiid"
+ instance_type = "t3.micro"
+}

MODIFY
tests/terraform/runner/test_runner.py
tests/terraform/runner/test_runner.py
@@ -495,6 +495,15 @@ class TestRunnerValid(unittest.TestCase):
# no need to join with a '/' because the TF runner adds it to the start of the file path
self.assertEqual(record.repo_file_path, f'/{file_rel_path}')
+ def test_runner_malformed_857(self):
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+
+ passing_tf_file_path = current_dir + "/resources/malformed_857/main.tf"
+
+ runner = Runner()
+ runner.run(root_folder=None, external_checks_dir=None, files=[passing_tf_file_path])
+ # If we get here all is well. :-) Failure would throw an exception.
+
def tearDown(self):
parser_registry.definitions_context = {}

Handle malformed input case (#858)

Fixes: 857