We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `checkov/terraform/parser.py`
Content:
```
1 import logging
2 import os
3 from os import path
4 
5 import hcl2
6 
7 
8 class Parser:
9     logger = logging.getLogger(__name__)
10 
11     def hcl2(self, directory, tf_definitions={}, parsing_errors={}):
12         modules_scan = []
13 
14         for file in os.listdir(directory):
15             if file.endswith(".tf"):
16                 tf_file = os.path.join(directory, file)
17                 if tf_file not in tf_definitions.keys():
18                     try:
19                         with(open(tf_file, 'r')) as file:
20                             file.seek(0)
21                             dict = hcl2.load(file)
22                             tf_defenition = dict
23                             tf_definitions[tf_file] = tf_defenition
24                             # TODO move from here
25                             # tf_defenitions = context_registry.enrich_context(tf_file,tf_defenitions)
26 
27                             for modules in dict.get("module", []):
28                                 for module in modules.values():
29                                     relative_path = module['source'][0]
30                                     abs_path = os.path.join(directory, relative_path)
31                                     modules_scan.append(abs_path)
32                     except Exception as e:
33                         self.logger.debug('failed while parsing file %s' % tf_file, exc_info=e)
34                         parsing_errors[tf_file] = e
35         for m in modules_scan:
36             if path.exists(m):
37                 self.hcl2(directory=m, tf_definitions=tf_definitions)
38 
39     def parse_file(self, file, tf_definitions={}, parsing_errors={}):
40         if file.endswith(".tf"):
41             try:
42                 with(open(file, 'r')) as tf_file:
43                     tf_file.seek(0)
44                     dict = hcl2.load(tf_file)
45                     tf_defenition = dict
46                     tf_definitions[file] = tf_defenition
47             except Exception as e:
48                 self.logger.debug('failed while parsing file %s' % file, exc_info=e)
49                 parsing_errors[file] = e
50
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
                     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)

{"golden_diff": "diff --git a/checkov/terraform/parser.py b/checkov/terraform/parser.py\n--- a/checkov/terraform/parser.py\n+++ b/checkov/terraform/parser.py\n@@ -18,13 +18,18 @@\n                     try:\n                         with(open(tf_file, 'r')) as file:\n                             file.seek(0)\n-                            dict = hcl2.load(file)\n-                            tf_defenition = dict\n-                            tf_definitions[tf_file] = tf_defenition\n+                            tf_definition = hcl2.load(file)\n+                            for resource_type in tf_definition.get('resource', []):\n+                                for resource in resource_type.values():\n+                                    for named_resource in resource.values():\n+                                        for dynamic_block in named_resource.get('dynamic', []):\n+                                            for dynamic_field_name, dynamic_field_value in dynamic_block.items():\n+                                                named_resource[dynamic_field_name] = dynamic_field_value['for_each']\n+                            tf_definitions[tf_file] = tf_definition\n                             # TODO move from here\n                             # tf_defenitions = context_registry.enrich_context(tf_file,tf_defenitions)\n \n-                            for modules in dict.get(\"module\", []):\n+                            for modules in tf_definition.get(\"module\", []):\n                                 for module in modules.values():\n                                     relative_path = module['source'][0]\n                                     abs_path = os.path.join(directory, relative_path)\n", "issue": "Dynamic blocks handling is partial\n**Describe the bug**\r\nAn S3 bucket with a dynamic `logging` block is considered a violation, even if a value was set for the variable externally.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\nS3 configuration:\r\n```\r\nresource \"aws_s3_bucket\" \"bridgecrew_cws_bucket\" {\r\n  count = var.existing_bucket_name == null ? 1 : 0\r\n\r\n  bucket        = local.bucket_name\r\n  acl               = \"private\"\r\n\r\n  versioning {\r\n    enabled = true\r\n  }\r\n\r\n  lifecycle_rule {\r\n    id      = \"Delete old log files\"\r\n    enabled = true\r\n\r\n    noncurrent_version_expiration {\r\n      days = var.log_file_expiration\r\n    }\r\n\r\n    expiration {\r\n      days = var.log_file_expiration\r\n    }\r\n  }\r\n\r\n  dynamic \"logging\" {\r\n    for_each = var.logs_bucket_id != null ? [var.logs_bucket_id] : []\r\n\r\n    content {\r\n      target_bucket = logging.value\r\n      target_prefix = \"/${local.bucket_name}\"\r\n    }\r\n  }\r\n\r\n  server_side_encryption_configuration {\r\n    rule {\r\n      apply_server_side_encryption_by_default {\r\n        kms_master_key_id = local.kms_key\r\n        sse_algorithm     = \"aws:kms\"\r\n      }\r\n    }\r\n  }\r\n\r\n  tags = {\r\n    Name = \"BridgecrewCWSBucket\"\r\n  }\r\n}\r\n```\r\n\r\n**Expected behavior**\r\nThe check should not fail\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: mac OSX Catalina\r\n - Checkov Version 1.0.167\r\n\r\n\nDocker command in README.md is wrong\n**Describe the bug**\r\nThe docker run command in the readme is incorrect and does not work.  It should be: \r\ndocker run -v /user/tf:/tf bridgecrew/checkov -d /tf\r\n\r\n\n", "before_files": [{"content": "import logging\nimport os\nfrom os import path\n\nimport hcl2\n\n\nclass Parser:\n    logger = logging.getLogger(__name__)\n\n    def hcl2(self, directory, tf_definitions={}, parsing_errors={}):\n        modules_scan = []\n\n        for file in os.listdir(directory):\n            if file.endswith(\".tf\"):\n                tf_file = os.path.join(directory, file)\n                if tf_file not in tf_definitions.keys():\n                    try:\n                        with(open(tf_file, 'r')) as file:\n                            file.seek(0)\n                            dict = hcl2.load(file)\n                            tf_defenition = dict\n                            tf_definitions[tf_file] = tf_defenition\n                            # TODO move from here\n                            # tf_defenitions = context_registry.enrich_context(tf_file,tf_defenitions)\n\n                            for modules in dict.get(\"module\", []):\n                                for module in modules.values():\n                                    relative_path = module['source'][0]\n                                    abs_path = os.path.join(directory, relative_path)\n                                    modules_scan.append(abs_path)\n                    except Exception as e:\n                        self.logger.debug('failed while parsing file %s' % tf_file, exc_info=e)\n                        parsing_errors[tf_file] = e\n        for m in modules_scan:\n            if path.exists(m):\n                self.hcl2(directory=m, tf_definitions=tf_definitions)\n\n    def parse_file(self, file, tf_definitions={}, parsing_errors={}):\n        if file.endswith(\".tf\"):\n            try:\n                with(open(file, 'r')) as tf_file:\n                    tf_file.seek(0)\n                    dict = hcl2.load(tf_file)\n                    tf_defenition = dict\n                    tf_definitions[file] = tf_defenition\n            except Exception as e:\n                self.logger.debug('failed while parsing file %s' % file, exc_info=e)\n                parsing_errors[file] = e\n", "path": "checkov/terraform/parser.py"}], "after_files": [{"content": "import logging\nimport os\nfrom os import path\n\nimport hcl2\n\n\nclass Parser:\n    logger = logging.getLogger(__name__)\n\n    def hcl2(self, directory, tf_definitions={}, parsing_errors={}):\n        modules_scan = []\n\n        for file in os.listdir(directory):\n            if file.endswith(\".tf\"):\n                tf_file = os.path.join(directory, file)\n                if tf_file not in tf_definitions.keys():\n                    try:\n                        with(open(tf_file, 'r')) as file:\n                            file.seek(0)\n                            tf_definition = hcl2.load(file)\n                            for resource_type in tf_definition.get('resource', []):\n                                for resource in resource_type.values():\n                                    for named_resource in resource.values():\n                                        for dynamic_block in named_resource.get('dynamic', []):\n                                            for dynamic_field_name, dynamic_field_value in dynamic_block.items():\n                                                named_resource[dynamic_field_name] = dynamic_field_value['for_each']\n                            tf_definitions[tf_file] = tf_definition\n                            # TODO move from here\n                            # tf_defenitions = context_registry.enrich_context(tf_file,tf_defenitions)\n\n                            for modules in tf_definition.get(\"module\", []):\n                                for module in modules.values():\n                                    relative_path = module['source'][0]\n                                    abs_path = os.path.join(directory, relative_path)\n                                    modules_scan.append(abs_path)\n                    except Exception as e:\n                        self.logger.debug('failed while parsing file %s' % tf_file, exc_info=e)\n                        parsing_errors[tf_file] = e\n        for m in modules_scan:\n            if path.exists(m):\n                self.hcl2(directory=m, tf_definitions=tf_definitions)\n\n    def parse_file(self, file, tf_definitions={}, parsing_errors={}):\n        if file.endswith(\".tf\"):\n            try:\n                with(open(file, 'r')) as tf_file:\n                    tf_file.seek(0)\n                    dict = hcl2.load(tf_file)\n                    tf_defenition = dict\n                    tf_definitions[file] = tf_defenition\n            except Exception as e:\n                self.logger.debug('failed while parsing file %s' % file, exc_info=e)\n                parsing_errors[file] = e\n", "path": "checkov/terraform/parser.py"}]}