Skip to content

Commit ffc2c69

Browse files
authored
fix(terraform): Improved bad performance pathlib check (#5939)
Made check for first to avoid heavy pathlib calculations
1 parent f1b5a55 commit ffc2c69

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

checkov/terraform/tf_parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,10 @@ def add_tfvars_with_source_dir(self, module: Module, source: str, source_dir: st
525525
if not self.external_variables_data:
526526
return
527527
for var_name, default, path in self.external_variables_data:
528-
if Path(source_dir) in Path(path).parents and ".tfvars" in path:
529-
block = [{var_name: {"default": default}}]
530-
module.add_blocks(BlockType.TF_VARIABLE, block, path, source)
528+
if ".tfvars" in path:
529+
if Path(source_dir) in Path(path).parents:
530+
block = [{var_name: {"default": default}}]
531+
module.add_blocks(BlockType.TF_VARIABLE, block, path, source)
531532

532533
def get_dirname(self, path: TFDefinitionKey) -> str:
533534
file_path = path.file_path

0 commit comments

Comments
 (0)