Repository: bridgecrewio/checkov

Issue:
Crash mentioned in issue #2370 still exist for AWS Batch Job with Fargate  
**Describe the issue**
Checkov is failing for Fargate AWS Batch Job with error - `[ERROR]  Failed to run check: Batch job does not define a privileged container for configuration`. I am using terraform `resource "aws_batch_job_definition"` and as per AWS document, Fargate Batch Jobs do not have Privileged parameters. [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-batch-jobdefinition-containerproperties.html#cfn-batch-jobdefinition-containerproperties-privileged](url)

**Examples**
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/batch_job_definition#fargate-platform-capability

**Exception Trace**
```
2022-08-19 15:22:00,858 [MainThread  ] [DEBUG]  Scanning file: /tf.json
2022-08-19 15:22:00,858 [MainThread  ] [DEBUG]  Should run check CKV_AWS_210: True
2022-08-19 15:22:00,858 [MainThread  ] [DEBUG]  Running check: Batch job does not define a privileged container on file /tf.json
2022-08-19 15:22:00,860 [MainThread  ] [ERROR]  Failed to run check: Batch job does not define a privileged container for configuration: {'container_properties': ['{"command":["echo","test"],"fargatePlatformConfiguration":{"platformVersion":"LATEST"},"image":"busybox","resourceRequirements":[{"type":"VCPU","value":"0.25"},{"type":"MEMORY","value":"512"}]}'], 'name': ['tf_test_batch_job_definition'], 'parameters': [None], 'platform_capabilities': [['FARGATE']], 'propagate_tags': [False], 'retry_strategy': [[]], 'tags': [None], 'timeout': [[]], 'type': ['container'], '__startline__': [14], '__endline__': [26], 'start_line': [13], 'end_line': [25], '__address__': 'aws_batch_job_definition.test', '__change_actions__': ['create']} at file: /tf.json
Process ForkProcess-4:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/local/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/checkov/common/parallelizer/parallel_runner.py", line 37, in func_wrapper
    result = original_func(item)
2022-08-19 15:22:00,862 [MainThread  ] [DEBUG]  Environment variable BITBUCKET_REPO_FULL_NAME was not set. Cannot fetch branch restrictions.
  File "/usr/local/lib/python3.8/site-packages/checkov/common/runners/runner_registry.py", line 83, in _parallel_run
    return runner.run(
  File "/usr/local/lib/python3.8/site-packages/checkov/terraform/plan_runner.py", line 74, in run
    self.check_tf_definition(report, root_folder, runner_filter)
  File "/usr/local/lib/python3.8/site-packages/checkov/terraform/plan_runner.py", line 92, in check_tf_definition
    self.run_block(definition[block_type], None, full_file_path, root_folder, report, scanned_file,
  File "/usr/local/lib/python3.8/site-packages/checkov/terraform/plan_runner.py", line 112, in run_block
    results = registry.scan(scanned_file, entity, [], runner_filter, report_type=CheckType.TERRAFORM_PLAN)
  File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py", line 126, in scan
    result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)
  File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check_registry.py", line 140, in run_check
    result = check.run(
  File "/usr/local/lib/python3.8/site-packages/checkov/common/checks/base_check.py", line 70, in run
    check_result["result"] = self.scan_entity_conf(entity_configuration, entity_type)
  File "/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/base_resource_check.py", line 43, in scan_entity_conf
    return self.scan_resource_conf(conf)
  File "/usr/local/lib/python3.8/site-packages/checkov/terraform/checks/resource/aws/BatchJobIsNotPrivileged.py", line 26, in scan_resource_conf
    if container.get("privileged"):
  File "/usr/local/lib/python3.8/site-packages/checkov/common/parsers/node.py", line 34, in __getattr__
    raise TemplateAttributeError(f'{name} is invalid')
checkov.common.parsers.node.TemplateAttributeError: get is invalid
```


**Desktop (please complete the following information):**
 - OS: [MacOS, Linux]
 - Checkov Version [2.1.137]

**Additional context**
The issue was also mentioned in #2370 and it was Fixed by https://github.com/bridgecrewio/checkov/pull/2372 but I don't see that the Fargate type was considered in the test.



Discussion:

Resolving patch:
diff --git a/checkov/terraform/checks/resource/aws/BatchJobIsNotPrivileged.py b/checkov/terraform/checks/resource/aws/BatchJobIsNotPrivileged.py
--- a/checkov/terraform/checks/resource/aws/BatchJobIsNotPrivileged.py
+++ b/checkov/terraform/checks/resource/aws/BatchJobIsNotPrivileged.py
@@ -1,28 +1,34 @@
+from __future__ import annotations
+
 import json
 import logging
+from typing import Any
 
 from checkov.common.models.enums import CheckResult, CheckCategories
 from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck
 
 
 class BatchJobIsNotPrivileged(BaseResourceCheck):
-    def __init__(self):
+    def __init__(self) -> None:
         name = "Batch job does not define a privileged container"
         id = "CKV_AWS_210"
-        supported_resources = ['aws_batch_job_definition']
-        categories = [CheckCategories.GENERAL_SECURITY]
+        supported_resources = ("aws_batch_job_definition",)
+        categories = (CheckCategories.GENERAL_SECURITY,)
         super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)
 
-    def scan_resource_conf(self, conf):
-        if conf.get("container_properties"):
-            if type(conf.get("container_properties")[0]) is str:
+    def scan_resource_conf(self, conf: dict[str, list[Any]]) -> CheckResult:
+        container_properties = conf.get("container_properties")
+        if container_properties:
+            if isinstance(container_properties[0], str):
                 try:
-                    container = json.loads(conf.get("container_properties")[0])
+                    container = json.loads(container_properties[0])
                 except json.JSONDecodeError as e:
                     logging.error(e)
                     return CheckResult.UNKNOWN
             else:
-                container = conf.get("container_properties")[0]
+                container = container_properties[0]
+            if not isinstance(container, dict):
+                return CheckResult.UNKNOWN
             if container.get("privileged"):
                 return CheckResult.FAILED
             return CheckResult.PASSED


Test patch:
diff --git a/tests/terraform/checks/resource/aws/example_BatchJobIsNotPrivileged/main.tf b/tests/terraform/checks/resource/aws/example_BatchJobIsNotPrivileged/main.tf
--- a/tests/terraform/checks/resource/aws/example_BatchJobIsNotPrivileged/main.tf
+++ b/tests/terraform/checks/resource/aws/example_BatchJobIsNotPrivileged/main.tf
@@ -171,4 +171,14 @@ resource "aws_batch_job_definition" "pass3" {
   })
 }
 
+# not a valid configuration
+resource "aws_batch_job_definition" "unknown3" {
+  name = "tf_test_batch_job_definition"
+  type = "container"
 
+  container_properties = [{
+    "image" : "busybox",
+    "memory" : 1024,
+    "vcpus" : 1,
+  }]
+}
diff --git a/tests/terraform/checks/resource/aws/test_BatchJobIsNotPrivileged.py b/tests/terraform/checks/resource/aws/test_BatchJobIsNotPrivileged.py
--- a/tests/terraform/checks/resource/aws/test_BatchJobIsNotPrivileged.py
+++ b/tests/terraform/checks/resource/aws/test_BatchJobIsNotPrivileged.py
@@ -31,6 +31,7 @@ def test(self):
         self.assertEqual(summary["failed"], 1)
         self.assertEqual(summary["skipped"], 0)
         self.assertEqual(summary["parsing_errors"], 0)
+        self.assertEqual(summary["resource_count"], 7)  # 3 unknown
 
         self.assertEqual(passing_resources, passed_check_resources)
         self.assertEqual(failing_resources, failed_check_resources)