Skip to content

Commit

Permalink
Merge pull request #3185 from snyk/feat/enable-iac-tf-vars-for-everyo…
Browse files Browse the repository at this point in the history
…ne-all-tests

Remove IaC TF Vars FF to make default flow for everyone [CFG-1829]
  • Loading branch information
ipapast authored May 31, 2022
2 parents 1ee4e6d + eedd239 commit 2868849
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 529 deletions.
21 changes: 7 additions & 14 deletions src/cli/commands/test/iac/local-execution/file-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,21 @@ 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 = {},
isTFVarSupportEnabled = false,
): Promise<ParsingResults> {
let tfFileData: IacFileData[] = [];
let nonTfFileData: IacFileData[] = [];

if (!isTFVarSupportEnabled) {
nonTfFileData = filesData.filter((fileData) =>
['tf', 'json', 'yaml', 'yml'].includes(fileData.fileType),
);
} else {
tfFileData = filesData.filter((fileData) =>
VALID_TERRAFORM_FILE_TYPES.includes(fileData.fileType),
);
nonTfFileData = filesData.filter(
(fileData) => !VALID_TERRAFORM_FILE_TYPES.includes(fileData.fileType),
);
}
tfFileData = filesData.filter((fileData) =>
VALID_TERRAFORM_FILE_TYPES.includes(fileData.fileType),
);
nonTfFileData = filesData.filter(
(fileData) => !VALID_TERRAFORM_FILE_TYPES.includes(fileData.fileType),
);

let { parsedFiles, failedFiles } = parseNonTerraformFiles(
nonTfFileData,
Expand Down
16 changes: 1 addition & 15 deletions src/cli/commands/test/iac/local-execution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
trackUsage,
} from './measurable-methods';
import { findAndLoadPolicy } from '../../../../../lib/policy';
import { isFeatureFlagSupportedForOrg } from '../../../../../lib/feature-flags';
import { NoFilesToScanError } from './file-loader';
import { processResults } from './process-results';
import { generateProjectAttributes, generateTags } from '../../../monitor';
Expand All @@ -32,7 +31,6 @@ import {
} from './directory-loader';
import { CustomError } from '../../../../../lib/errors';
import { getErrorStringCode } from './error-utils';
import { FeatureFlagError } from './assert-iac-options-flag';

// this method executes the local processing engine and then formats the results to adapt with the CLI output.
// this flow is the default GA flow for IAC scanning.
Expand All @@ -50,13 +48,6 @@ export async function test(

const policy = await findAndLoadPolicy(pathToScan, 'iac', options);

const isTFVarSupportEnabled = (
await isFeatureFlagSupportedForOrg(
'iacTerraformVarSupport',
iacOrgSettings.meta.org,
)
).ok;

let allParsedFiles: IacFileParsed[] = [],
allFailedFiles: IacFileParseFailure[] = [];
const allDirectories = getAllDirectoriesForPath(
Expand All @@ -73,7 +64,7 @@ export async function test(
);
if (
currentDirectory === pathToScan &&
shouldLoadVarDefinitionsFile(options, isTFVarSupportEnabled)
shouldLoadVarDefinitionsFile(options)
) {
const varDefinitionsFilePath = options['var-file'];
filePathsInDirectory.push(varDefinitionsFilePath);
Expand All @@ -82,7 +73,6 @@ export async function test(
const { parsedFiles, failedFiles } = await parseFiles(
filesToParse,
options,
isTFVarSupportEnabled,
);
allParsedFiles = allParsedFiles.concat(parsedFiles);
allFailedFiles = allFailedFiles.concat(failedFiles);
Expand Down Expand Up @@ -182,12 +172,8 @@ function parseAttributes(options: IaCTestFlags) {

function shouldLoadVarDefinitionsFile(
options: IaCTestFlags,
isTFVarSupportEnabled = false,
): options is IaCTestFlags & { 'var-file': string } {
if (options['var-file']) {
if (!isTFVarSupportEnabled) {
throw new FeatureFlagError('var-file', 'iacTerraformVarSupport');
}
if (!existsSync(options['var-file'])) {
throw new InvalidVarFilePath(options['var-file']);
}
Expand Down
8 changes: 0 additions & 8 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getFixturePath } from '../jest/util/getFixturePath';
const featureFlagDefaults = (): Map<string, boolean> => {
return new Map([
['cliFailFast', false],
['iacTerraformVarSupport', false],
['iacCliOutputRelease', false],
]);
};
Expand Down Expand Up @@ -341,13 +340,6 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
return;
}

if (org === 'tf-lang-support' && flag === 'iacTerraformVarSupport') {
res.send({
ok: true,
});
return;
}

if (featureFlags.has(flag)) {
const ffEnabled = featureFlags.get(flag);
if (ffEnabled) {
Expand Down
12 changes: 5 additions & 7 deletions test/jest/acceptance/iac/iac-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,34 +325,32 @@ Project path: ${filePath}
expect(stdout).toContain(
'Tested sg_open_ssh.tf for known issues, found 1 issues',
);
expect(stdout).toContain(
'Tested vars.tf for known issues, found 0 issues',
);
expect(stdout).toContain('Tested vars.tf for known issues, found');
expect(stdout).toContain(
`Tested ${pathLib.join(
'var_deref',
'sg_open_ssh.tf',
)} for known issues, found 0 issues`,
)} for known issues, found`,
);
expect(stdout).toContain(
`Tested ${pathLib.join(
'var_deref',
'variables.tf',
)} for known issues, found 0 issues`,
)} for known issues, found`,
);
expect(stdout).toContain(
`Tested ${pathLib.join(
'var_deref',
'nested_var_deref',
'sg_open_ssh.tf',
)} for known issues, found 0 issues`,
)} for known issues, found`,
);
expect(stdout).toContain(
`Tested ${pathLib.join(
'var_deref',
'nested_var_deref',
'variables.tf',
)} for known issues, found 0 issues`,
)} for known issues, found`,
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/jest/acceptance/iac/test-directory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Directory scan', () => {
expect(stdout).toContain('Failed to parse YAML file');
expect(stdout).toContain('Failed to parse JSON file');
expect(stdout).toContain(
'28 projects, 20 contained issues. Failed to test 5 projects.',
'28 projects, 22 contained issues. Failed to test 5 projects.',
);
expect(exitCode).toBe(1);
});
Expand Down
Loading

0 comments on commit 2868849

Please sign in to comment.