Repository: bridgecrewio/checkov

Issue:
external-modules-download-path not recognized
**Describe the bug**
When using --external-modules-download-path test, module are downloaded inside .external_modules folder instead of test.

**To Reproduce**
Steps to reproduce the behavior:

➜  `checkov --external-modules-download-path test --config-file ../../.checkov.yml --show-config`

```
Command Line Args:   --external-modules-download-path test --config-file ../../.checkov.yml --show-config
Config File (../../.checkov.yml):
  compact:           True
  directory:         ['.']
  download-external-modules:True
  evaluate-variables:True
  framework:         terraform
  output:            cli
  quiet:             True
  skip-check:        ['CKV_AWS_2', 'CKV_AWS_8', 'CKV_AWS_9', 'CKV_AWS_19', 'CKV_AWS_20', 'CKV_AWS_103', 'CKV_AWS_111', 'CKV_AWS_128', 'CKV_AWS_143', 'CKV_AWS_145', 'CKV_AWS_162', 'CKV2_AWS_5', 'CKV2_AWS_8', 'CKV2_AWS_11', 'CKV2_AWS_14', 'CKV2_AWS_19', 'CKV2_AWS_21', 'CKV2_AWS_22', 'CKV2_AWS_28']
Defaults:
  --branch:          master
```

➜  `checkov --external-modules-download-path test --config-file ../../.checkov.yml`

```
       _               _
   ___| |__   ___  ___| | _______   __
  / __| '_ \ / _ \/ __| |/ / _ \ \ / /
 | (__| | | |  __/ (__|   < (_) \ V /
  \___|_| |_|\___|\___|_|\_\___/ \_/

By bridgecrew.io | version: 2.0.427

terraform scan results:

Passed checks: 73, Failed checks: 0, Skipped checks: 0
```

➜  `cat ../../.checkov.yml`

```
compact: true
directory:
  - .
download-external-modules: true
evaluate-variables: true
framework: terraform
output: cli
quiet: true
skip-check:
  - CKV_AWS_2
  - CKV_AWS_8
  - CKV_AWS_9
  - CKV_AWS_19
  - CKV_AWS_20
  - CKV_AWS_103
  - CKV_AWS_111
  - CKV_AWS_128
  - CKV_AWS_143
  - CKV_AWS_145
  - CKV_AWS_162
  - CKV2_AWS_5
  - CKV2_AWS_8
  - CKV2_AWS_11
  - CKV2_AWS_14
  - CKV2_AWS_19
  - CKV2_AWS_21
  - CKV2_AWS_22
  - CKV2_AWS_28
```
 
➜  `ls -lah`

`drwxr-xr-x   3   96B Sep 20 13:30 .external_modules`



Discussion:

Resolving patch:
diff --git a/checkov/terraform/graph_manager.py b/checkov/terraform/graph_manager.py
--- a/checkov/terraform/graph_manager.py
+++ b/checkov/terraform/graph_manager.py
@@ -1,7 +1,9 @@
 import logging
-from typing import List, Optional
+from typing import List, Optional, Dict, Type, Tuple, Any
 
+from checkov.common.graph.graph_builder.local_graph import LocalGraph
 from checkov.common.graph.graph_manager import GraphManager
+from checkov.common.util.consts import DEFAULT_EXTERNAL_MODULES_DIR
 from checkov.terraform.graph_builder.local_graph import TerraformLocalGraph
 from checkov.terraform.parser import Parser
 
@@ -10,12 +12,28 @@ class TerraformGraphManager(GraphManager):
     def __init__(self, db_connector, source=''):
         super().__init__(db_connector=db_connector, parser=Parser(), source=source)
 
-    def build_graph_from_source_directory(self, source_dir, render_variables=True, local_graph_class=TerraformLocalGraph,
-                                          parsing_errors=None, download_external_modules=False, excluded_paths: List[str]=None,
-                                          vars_files: Optional[List[str]] = None):
+    def build_graph_from_source_directory(
+        self,
+        source_dir: str,
+        render_variables: bool = True,
+        local_graph_class: Type[LocalGraph] = TerraformLocalGraph,
+        parsing_errors: Optional[Dict[str, Exception]] = None,
+        download_external_modules: bool = False,
+        external_modules_download_path: str = DEFAULT_EXTERNAL_MODULES_DIR,
+        excluded_paths: Optional[List[str]] = None,
+        vars_files: Optional[List[str]] = None
+    ) -> Tuple[LocalGraph, Dict[str, Dict[str, Any]]]:
         logging.info('Parsing HCL files in source dir')
         module, module_dependency_map, tf_definitions = \
-            self.parser.parse_hcl_module(source_dir, self.source, download_external_modules, parsing_errors, excluded_paths=excluded_paths, vars_files=vars_files)
+            self.parser.parse_hcl_module(
+                source_dir=source_dir,
+                source=self.source,
+                download_external_modules=download_external_modules,
+                external_modules_download_path=external_modules_download_path,
+                parsing_errors=parsing_errors,
+                excluded_paths=excluded_paths,
+                vars_files=vars_files
+            )
 
         logging.info('Building graph from parsed module')
         local_graph = local_graph_class(module, module_dependency_map)
diff --git a/checkov/terraform/parser.py b/checkov/terraform/parser.py
--- a/checkov/terraform/parser.py
+++ b/checkov/terraform/parser.py
@@ -452,7 +452,16 @@ def _load_modules(self, root_dir: str, module_loader_registry: ModuleLoaderRegis
             deep_merge.merge(self.out_evaluations_context, all_module_evaluations_context)
         return skipped_a_module
 
-    def parse_hcl_module(self, source_dir, source, download_external_modules=False, parsing_errors=None, excluded_paths: List[str]=None, vars_files: Optional[List[str]]=None):
+    def parse_hcl_module(
+        self,
+        source_dir: str,
+        source: str,
+        download_external_modules: bool = False,
+        external_modules_download_path: str = DEFAULT_EXTERNAL_MODULES_DIR,
+        parsing_errors: Optional[Dict[str, Exception]] = None,
+        excluded_paths: Optional[List[str]] = None,
+        vars_files: Optional[List[str]] = None
+    ) -> Tuple[Module, Dict[str, List[List[str]]], Dict[str, Dict[str, Any]]]:
         tf_definitions = {}
         self.parse_directory(directory=source_dir, out_definitions=tf_definitions, out_evaluations_context={},
                              out_parsing_errors=parsing_errors if parsing_errors is not None else {},
diff --git a/checkov/terraform/runner.py b/checkov/terraform/runner.py
--- a/checkov/terraform/runner.py
+++ b/checkov/terraform/runner.py
@@ -70,12 +70,15 @@ def run(self, root_folder, external_checks_dir=None, files=None, runner_filter=R
             if root_folder:
                 root_folder = os.path.abspath(root_folder)
 
-                local_graph, tf_definitions = \
-                    self.graph_manager.build_graph_from_source_directory(root_folder,
-                                                                         local_graph_class=self.graph_class,
-                                                                         download_external_modules=runner_filter.download_external_modules,
-                                                                         parsing_errors=parsing_errors, excluded_paths=runner_filter.excluded_paths,
-                                                                         vars_files=runner_filter.var_files)
+                local_graph, tf_definitions = self.graph_manager.build_graph_from_source_directory(
+                    source_dir=root_folder,
+                    local_graph_class=self.graph_class,
+                    download_external_modules=runner_filter.download_external_modules,
+                    external_modules_download_path=runner_filter.external_modules_download_path,
+                    parsing_errors=parsing_errors,
+                    excluded_paths=runner_filter.excluded_paths,
+                    vars_files=runner_filter.var_files
+                )
             elif files:
                 files = [os.path.abspath(file) for file in files]
                 root_folder = os.path.split(os.path.commonprefix(files))[0]


Test patch: