Repository: bridgecrewio/checkov

Issue:
CKV_AWS_134: Skip Memcache engine
**Describe the bug**
"snapshot_retention_limit" - parameter only for "Redis" engine and in my TF module for Memcache it doesn't exist. But when I run "checkov" I got the following:

```
Check: CKV_AWS_134: "Ensure that Amazon ElastiCache Redis clusters have automatic backup turned on"
	FAILED for resource: aws_elasticache_cluster.memcached
	File: /tf.json:0-0
	Guide: https://docs.bridgecrew.io/docs/ensure-that-amazon-elasticache-redis-clusters-have-automatic-backup-turned-on
```

**Terraform module**
```
### ElastiCache Memcached CLuster
resource "aws_elasticache_cluster" "memcached" {
  cluster_id = lower("${var.basename}-Memcached-Cluster")

  engine               = var.engine
  engine_version       = var.engine_version
  port                 = var.port
  parameter_group_name = module.common.parameter_group_name

  node_type       = var.node_type
  num_cache_nodes = var.num_cache_nodes
  az_mode         = var.az_mode

  subnet_group_name  = module.common.subnet_group_name
  security_group_ids = [module.common.sg_id]

  apply_immediately = true

  tags = var.tags
}
```

**memcache.tf**
```
### ElastiCache: Memcashed Cluster
module "elasticache-memcached" {
  source = "../../modules/elasticache/memcached"

  basename = local.basename
  vpc_id   = module.vpc.id
  subnets  = module.private-subnets.ids

  engine_version         = "1.6.6"
  parameter_group_family = "memcached1.6"
  node_type              = "cache.t3.small"
  num_cache_nodes        = 2

  # Enable az_mode, when num_cache_nodes > 1
  az_mode = "cross-az"

  cidr_groups = { ALL = "0.0.0.0/0" }

  tags = local.base_tags
}
```

**Expected behavior**
If engine is "memcache" then check must be skipped.

**Desktop:**
 - OS: macOS Big Sur - 11.2.1
 - Checkov Version: 2.0.77



Discussion:

Resolving patch:
diff --git a/checkov/terraform/checks/resource/aws/ElasticCacheAutomaticBackup.py b/checkov/terraform/checks/resource/aws/ElasticCacheAutomaticBackup.py
--- a/checkov/terraform/checks/resource/aws/ElasticCacheAutomaticBackup.py
+++ b/checkov/terraform/checks/resource/aws/ElasticCacheAutomaticBackup.py
@@ -6,13 +6,24 @@ class ElasticCacheAutomaticBackup(BaseResourceNegativeValueCheck):
     def __init__(self):
         name = "Ensure that Amazon ElastiCache Redis clusters have automatic backup turned on"
         id = "CKV_AWS_134"
-        supported_resources = ['aws_elasticache_cluster']
+        supported_resources = ["aws_elasticache_cluster"]
         categories = [CheckCategories.BACKUP_AND_RECOVERY]
-        super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources,
-                         missing_attribute_result=CheckResult.FAILED)
+        super().__init__(
+            name=name,
+            id=id,
+            categories=categories,
+            supported_resources=supported_resources,
+            missing_attribute_result=CheckResult.FAILED,
+        )
+
+    def scan_resource_conf(self, conf):
+        if conf.get("engine") == ["memcached"]:
+            return CheckResult.UNKNOWN
+
+        return super().scan_resource_conf(conf)
 
     def get_inspected_key(self):
-        return 'snapshot_retention_limit'
+        return "snapshot_retention_limit"
 
     def get_forbidden_values(self):
         return [0]


Test patch:
diff --git a/tests/graph/terraform/graph_builder/test_graph_builder.py b/tests/graph/terraform/graph_builder/test_graph_builder.py
--- a/tests/graph/terraform/graph_builder/test_graph_builder.py
+++ b/tests/graph/terraform/graph_builder/test_graph_builder.py
@@ -131,7 +131,7 @@ def test_build_graph_with_linked_registry_modules(self):
                                                                                       render_variables=True,
                                                                                       download_external_modules=True)
 
-        outputs_vpcs = self.get_vertex_by_name_and_type(local_graph, BlockType.OUTPUT, 'this_security_group_vpc_id',
+        outputs_vpcs = self.get_vertex_by_name_and_type(local_graph, BlockType.OUTPUT, 'security_group_vpc_id',
                                                         multiple=True)
         resource_flow_log = self.get_vertex_by_name_and_type(local_graph, BlockType.RESOURCE,
                                                              'aws_flow_log.related_flow_log')
diff --git a/tests/graph/terraform/resources/modules/registry_security_group_inner_module/main.tf b/tests/graph/terraform/resources/modules/registry_security_group_inner_module/main.tf
--- a/tests/graph/terraform/resources/modules/registry_security_group_inner_module/main.tf
+++ b/tests/graph/terraform/resources/modules/registry_security_group_inner_module/main.tf
@@ -10,5 +10,5 @@ module "web_server_sg" {
 
 resource "aws_flow_log" "related_flow_log" {
   traffic_type = ""
-  vpc_id = module.web_server_sg.this_security_group_vpc_id
+  vpc_id = module.web_server_sg.security_group_vpc_id
 }
\ No newline at end of file
diff --git a/tests/terraform/checks/resource/aws/example_ElasticCacheAutomaticBackup/main.tf b/tests/terraform/checks/resource/aws/example_ElasticCacheAutomaticBackup/main.tf
new file mode 100644
--- /dev/null
+++ b/tests/terraform/checks/resource/aws/example_ElasticCacheAutomaticBackup/main.tf
@@ -0,0 +1,41 @@
+# pass
+
+resource "aws_elasticache_cluster" "enabled" {
+  cluster_id           = "cluster"
+  engine               = "redis"
+  node_type            = "cache.m5.large"
+  num_cache_nodes      = 1
+  parameter_group_name = "default.redis6.x"
+
+  snapshot_retention_limit = 5
+}
+
+# failure
+
+resource "aws_elasticache_cluster" "default" {
+  cluster_id           = "cluster"
+  engine               = "redis"
+  node_type            = "cache.m5.large"
+  num_cache_nodes      = 1
+  parameter_group_name = "default.redis6.x"
+}
+
+resource "aws_elasticache_cluster" "disabled" {
+  cluster_id           = "cluster"
+  engine               = "redis"
+  node_type            = "cache.m5.large"
+  num_cache_nodes      = 1
+  parameter_group_name = "default.redis6.x"
+
+  snapshot_retention_limit = 0
+}
+
+# unknown
+
+resource "aws_elasticache_cluster" "memcached" {
+  cluster_id           = "cluster"
+  engine               = "memcached"
+  node_type            = "cache.m5.large"
+  num_cache_nodes      = 1
+  parameter_group_name = "default.memcached1.6 "
+}
diff --git a/tests/terraform/checks/resource/aws/test_ElasticCacheAutomaticBackup.py b/tests/terraform/checks/resource/aws/test_ElasticCacheAutomaticBackup.py
--- a/tests/terraform/checks/resource/aws/test_ElasticCacheAutomaticBackup.py
+++ b/tests/terraform/checks/resource/aws/test_ElasticCacheAutomaticBackup.py
@@ -1,62 +1,39 @@
+import os
 import unittest
-import hcl2
 
+from checkov.runner_filter import RunnerFilter
 from checkov.terraform.checks.resource.aws.ElasticCacheAutomaticBackup import check
-from checkov.common.models.enums import CheckResult
+from checkov.terraform.runner import Runner
 
 
 class TestElasticCacheAutomaticBackup(unittest.TestCase):
+    def test(self):
+        runner = Runner()
+        current_dir = os.path.dirname(os.path.realpath(__file__))
 
-    def test_failure(self):
-        hcl_res = hcl2.loads("""
-                resource "aws_elasticache_cluster" "example" {
-                  cluster_id           = "cluster-example"
-                  engine               = "redis"
-                  node_type            = "cache.m4.large"
-                  num_cache_nodes      = 1
-                  parameter_group_name = "default.redis3.2"
-                  engine_version       = "3.2.10"
-                  port                 = 6379
-                  snapshot_retention_limit = 0
-                }
-        """)
-        resource_conf = hcl_res['resource'][0]['aws_elasticache_cluster']['example']
-        scan_result = check.scan_resource_conf(conf=resource_conf)
-        self.assertEqual(CheckResult.FAILED, scan_result)
-
-    def test_failure1(self):
-        hcl_res = hcl2.loads("""
-                resource "aws_elasticache_cluster" "example" {
-                  cluster_id           = "cluster-example"
-                  engine               = "redis"
-                  node_type            = "cache.m4.large"
-                  num_cache_nodes      = 1
-                  parameter_group_name = "default.redis3.2"
-                  engine_version       = "3.2.10"
-                  port                 = 6379
-                }
-        """)
-        resource_conf = hcl_res['resource'][0]['aws_elasticache_cluster']['example']
-        scan_result = check.scan_resource_conf(conf=resource_conf)
-        self.assertEqual(CheckResult.FAILED, scan_result)
-
-    def test_success(self):
-        hcl_res = hcl2.loads("""
-                resource "aws_elasticache_cluster" "example" {
-                  cluster_id           = "cluster-example"
-                  engine               = "redis"
-                  node_type            = "cache.m4.large"
-                  num_cache_nodes      = 1
-                  parameter_group_name = "default.redis3.2"
-                  engine_version       = "3.2.10"
-                  port                 = 6379
-                  snapshot_retention_limit = 5
-                }
-        """)
-        resource_conf = hcl_res['resource'][0]['aws_elasticache_cluster']['example']
-        scan_result = check.scan_resource_conf(conf=resource_conf)
-        self.assertEqual(CheckResult.PASSED, scan_result)
-
-
-if __name__ == '__main__':
+        test_files_dir = current_dir + "/example_ElasticCacheAutomaticBackup"
+        report = runner.run(root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id]))
+        summary = report.get_summary()
+
+        passing_resources = {
+            "aws_elasticache_cluster.enabled",
+        }
+        failing_resources = {
+            "aws_elasticache_cluster.default",
+            "aws_elasticache_cluster.disabled",
+        }
+
+        passed_check_resources = set([c.resource for c in report.passed_checks])
+        failed_check_resources = set([c.resource for c in report.failed_checks])
+
+        self.assertEqual(summary["passed"], 1)
+        self.assertEqual(summary["failed"], 2)
+        self.assertEqual(summary["skipped"], 0)
+        self.assertEqual(summary["parsing_errors"], 0)
+
+        self.assertEqual(passing_resources, passed_check_resources)
+        self.assertEqual(failing_resources, failed_check_resources)
+
+
+if __name__ == "__main__":
     unittest.main()