Skip to content

Commit

Permalink
feat: add debug logs for tf vars
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Feb 22, 2022
1 parent c2f7e94 commit 356abe8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/snyk/snyk-iac-parsers v0.3.0
github.com/snyk/snyk-iac-parsers v0.4.0
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ github.com/snyk/snyk-iac-parsers v0.1.0 h1:+VHQorhJ0iro0EwCJR2kNFYpkQ6EsfWSVi3xY
github.com/snyk/snyk-iac-parsers v0.1.0/go.mod h1:vmR6e9WfglVPO2Y82lW49Sb5jiGb13FXGwJGNtVRBcw=
github.com/snyk/snyk-iac-parsers v0.2.0 h1:bc48Ra3U3spo5wl6XogFoT4N7VlkxCGBM3Cq0rjd0C8=
github.com/snyk/snyk-iac-parsers v0.2.0/go.mod h1:vmR6e9WfglVPO2Y82lW49Sb5jiGb13FXGwJGNtVRBcw=
github.com/snyk/snyk-iac-parsers v0.3.0 h1:WusEK8AT1TiFbkTPVtfJohyGwtQNWBHVeruLVAA2ueI=
github.com/snyk/snyk-iac-parsers v0.3.0/go.mod h1:vmR6e9WfglVPO2Y82lW49Sb5jiGb13FXGwJGNtVRBcw=
github.com/snyk/snyk-iac-parsers v0.4.0 h1:qTuxHULxDlpk0j5zhfG4L/66ags4BpfW2suz6JPvqgg=
github.com/snyk/snyk-iac-parsers v0.4.0/go.mod h1:vmR6e9WfglVPO2Y82lW49Sb5jiGb13FXGwJGNtVRBcw=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
19 changes: 18 additions & 1 deletion src/cli/commands/test/iac-local-execution/file-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { parseYAMLOrJSONFileData } from './yaml-parser';
import hclToJsonV2 from './parsers/hcl-to-json-v2';
import { IacProjectType } from '../../../../lib/iac/constants';

import * as Debug from 'debug';
const debug = Debug('snyk-test');

export async function parseFiles(
filesData: IacFileData[],
options: IaCTestFlags = {},
Expand Down Expand Up @@ -59,10 +62,17 @@ export function parseTerraformFiles(filesData: IacFileData[]): ParsingResults {
map[fileData.filePath] = fileData.fileContent;
return map;
}, {});
const { parsedFiles, failedFiles } = hclToJsonV2(files);
const { parsedFiles, failedFiles, debugLogs } = hclToJsonV2(files);

// only throw an error when there were multiple files provided
if (filesData.length === 1 && Object.keys(failedFiles).length === 1) {
if (debugLogs[filesData[0].filePath]) {
debug(
'File %s failed to parse with: %s',
filesData[0].filePath,
debugLogs[filesData[0].filePath],
);
}
throw new FailedToParseTerraformFileError(filesData[0].filePath);
}

Expand All @@ -79,6 +89,13 @@ export function parseTerraformFiles(filesData: IacFileData[]): ParsingResults {
engineType: EngineType.Terraform,
});
} else if (failedFiles[fileData.filePath]) {
if (debugLogs[fileData.filePath]) {
debug(
'File %s failed to parse with: %s',
fileData.filePath,
debugLogs[fileData.filePath],
);
}
parsingResults.failedFiles.push(
generateFailedParsedFile(
fileData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type MapOfFiles = Record<FilePath, FileContent>;
type ParsedResults = {
parsedFiles: MapOfFiles;
failedFiles: MapOfFiles;
debugLogs: MapOfFiles;
};

interface HclToJsonArtifact {
Expand Down

Large diffs are not rendered by default.

0 comments on commit 356abe8

Please sign in to comment.