Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terraform): Add debug logs to yaml parsing logic #3718

Merged
merged 1 commit into from
Oct 23, 2022
Merged
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: 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