Skip to content

Commit

Permalink
fix(terraform): Add debug logs to yaml parsing logic (#3718)
Browse files Browse the repository at this point in the history
Add debug logs to yaml parsing logic
  • Loading branch information
nimrodkor authored Oct 23, 2022
1 parent 0ecf1c2 commit 779d096
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions checkov/cloudformation/cfn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def _parse_file(file):
else:
out_parsing_errors.update({file: 'Resource Properties is not a dictionary'})
else:
if parsing_errors:
logging.debug(f'File {file} had the following parsing errors: {parsing_errors}')
logging.debug(f"Parsed file {file} incorrectly {template}")
except (TypeError, ValueError):
logging.warning(f"CloudFormation skipping {file} as it is not a valid CF template")
Expand Down
3 changes: 3 additions & 0 deletions checkov/cloudformation/parser/cfn_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ def load(filename: Path, content_type: ContentType) -> Tuple[DictNode, List[Tupl
content = str(from_path(filename).best())

if content_type == ContentType.CFN and "Resources" not in content:
logging.debug(f'File {filename} is expected to be a CFN template but has no Resources attribute')
return {}, []
elif content_type == ContentType.SLS and "provider" not in content:
logging.debug(f'File {filename} is expected to be an SLS template but has no provider attribute')
return {}, []
elif content_type == ContentType.TFPLAN and "planned_values" not in content:
logging.debug(f'File {filename} is expected to be a TFPLAN file but has no planned_values attribute')
return {}, []

file_lines = [(idx + 1, line) for idx, line in enumerate(content.splitlines(keepends=True))]
Expand Down

0 comments on commit 779d096

Please sign in to comment.