Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkov/terraform/module_loading/module_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def find_modules(path: str, loaded_files_cache: Optional[Dict[str, Any]] = None,
if parsing_errors is None:
parsing_errors = {}

excluded_paths_regex = re.compile('|'.join(f"({excluded_paths})")) if excluded_paths else None
excluded_paths_regex = re.compile('|'.join(f"({p})" for p in excluded_paths)) if excluded_paths else None
for root, _, full_file_names in os.walk(path):
for file_name in full_file_names:
if not file_name.endswith(".tf"):
Expand Down
12 changes: 12 additions & 0 deletions tests/terraform/module_loading/test_tf_module_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_module_finder_nested_blocks(self):
self.assertEqual(1, len(modules))
self.assertEqual("3.14.0", modules[0].version)

def test_module_finder_excluded_paths_multiple_patterns(self):
cur_dir = os.path.abspath(os.path.dirname(__file__))
src_dir = os.path.join(cur_dir, 'data', 'tf_module_downloader')
# public_modules/main.tf defines two modules and
# private_registry_modules/main.tf defines one. Excluding
# public_modules leaves just the private one.
modules = find_modules(
src_dir,
excluded_paths=['public_modules', 'no_such_dir'],
)
self.assertEqual(1, len(modules))

def test_downloader(self):
modules = find_modules(self.get_src_dir())

Expand Down
Loading