Repository: bridgecrewio/checkov

Issue:
Dynamic blocks handling is partial
**Describe the bug**
An S3 bucket with a dynamic `logging` block is considered a violation, even if a value was set for the variable externally.

**To Reproduce**
Steps to reproduce the behavior:
S3 configuration:
```
resource "aws_s3_bucket" "bridgecrew_cws_bucket" {
  count = var.existing_bucket_name == null ? 1 : 0

  bucket        = local.bucket_name
  acl               = "private"

  versioning {
    enabled = true
  }

  lifecycle_rule {
    id      = "Delete old log files"
    enabled = true

    noncurrent_version_expiration {
      days = var.log_file_expiration
    }

    expiration {
      days = var.log_file_expiration
    }
  }

  dynamic "logging" {
    for_each = var.logs_bucket_id != null ? [var.logs_bucket_id] : []

    content {
      target_bucket = logging.value
      target_prefix = "/${local.bucket_name}"
    }
  }

  server_side_encryption_configuration {
    rule {
      apply_server_side_encryption_by_default {
        kms_master_key_id = local.kms_key
        sse_algorithm     = "aws:kms"
      }
    }
  }

  tags = {
    Name = "BridgecrewCWSBucket"
  }
}
```

**Expected behavior**
The check should not fail

**Desktop (please complete the following information):**
 - OS: mac OSX Catalina
 - Checkov Version 1.0.167


Docker command in README.md is wrong
**Describe the bug**
The docker run command in the readme is incorrect and does not work.  It should be: 
docker run -v /user/tf:/tf bridgecrew/checkov -d /tf




Discussion:

Resolving patch:
diff --git a/checkov/terraform/parser.py b/checkov/terraform/parser.py
--- a/checkov/terraform/parser.py
+++ b/checkov/terraform/parser.py
@@ -18,13 +18,18 @@ def hcl2(self, directory, tf_definitions={}, parsing_errors={}):
                     try:
                         with(open(tf_file, 'r')) as file:
                             file.seek(0)
-                            dict = hcl2.load(file)
-                            tf_defenition = dict
-                            tf_definitions[tf_file] = tf_defenition
+                            tf_definition = hcl2.load(file)
+                            for resource_type in tf_definition.get('resource', []):
+                                for resource in resource_type.values():
+                                    for named_resource in resource.values():
+                                        for dynamic_block in named_resource.get('dynamic', []):
+                                            for dynamic_field_name, dynamic_field_value in dynamic_block.items():
+                                                named_resource[dynamic_field_name] = dynamic_field_value['for_each']
+                            tf_definitions[tf_file] = tf_definition
                             # TODO move from here
                             # tf_defenitions = context_registry.enrich_context(tf_file,tf_defenitions)
 
-                            for modules in dict.get("module", []):
+                            for modules in tf_definition.get("module", []):
                                 for module in modules.values():
                                     relative_path = module['source'][0]
                                     abs_path = os.path.join(directory, relative_path)


Test patch:
diff --git a/tests/terraform/runner/resources/example/example.tf b/tests/terraform/runner/resources/example/example.tf
--- a/tests/terraform/runner/resources/example/example.tf
+++ b/tests/terraform/runner/resources/example/example.tf
@@ -416,4 +416,50 @@ resource "aws_iam_user_policy" "lb_ro" {
   ]
 }
 EOF
+}
+
+resource "aws_s3_bucket" "bridgecrew_cws_bucket" {
+  count = var.existing_bucket_name == null ? 1 : 0
+
+  bucket        = local.bucket_name
+  acl           = "private"
+
+  versioning {
+    enabled = true
+  }
+
+  lifecycle_rule {
+    id      = "Delete old log files"
+    enabled = true
+
+    noncurrent_version_expiration {
+      days = var.log_file_expiration
+    }
+
+    expiration {
+      days = var.log_file_expiration
+    }
+  }
+
+  dynamic "logging" {
+    for_each = var.logs_bucket_id != null ? [var.logs_bucket_id] : []
+
+    content {
+      target_bucket = logging.value
+      target_prefix = "/${local.bucket_name}"
+    }
+  }
+
+  server_side_encryption_configuration {
+    rule {
+      apply_server_side_encryption_by_default {
+        kms_master_key_id = local.kms_key
+        sse_algorithm     = "aws:kms"
+      }
+    }
+  }
+
+  tags = {
+    Name = "BridgecrewCWSBucket"
+  }
 }
\ No newline at end of file