Skip to content

Commit

Permalink
Merge pull request #3823 from snyk/feat/iac-cloud-context
Browse files Browse the repository at this point in the history
[CTX-58] feat: cloud context for IaC tests
  • Loading branch information
Craig Furman authored Sep 6, 2022
2 parents da41e69 + b9c1a10 commit b46e07b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/test/iac/local-execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export type IaCTestFlags = Pick<
path?: string;
// Allows the caller to provide the path to a WASM bundle.
rules?: string;
'cloud-context'?: string;
// Tags and attributes
'project-tags'?: string;
'project-environment'?: string;
Expand Down
17 changes: 17 additions & 0 deletions src/cli/commands/test/iac/v2/assert-iac-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const keys: (keyof IaCTestFlags)[] = [
'experimental',
'var-file',
'detectionDepth',
'cloud-context',
// PolicyOptions
'ignore-policy',
'policy-path',
Expand Down Expand Up @@ -57,6 +58,10 @@ export function assertIacV2Options(options: IaCTestFlags): void {
if (options.scan) {
assertTerraformPlanModes(options.scan as string);
}

if (options['cloud-context']) {
assertCloudContextOptions(options['cloud-context']);
}
}

function assertSeverityOptions(severity: SEVERITY) {
Expand All @@ -79,3 +84,15 @@ function assertVarFileOptions(filePath: string) {
throw new FlagValueError('var-file', filePath, '.tfvars file');
}
}

function assertCloudContextOptions(cloudContext: string) {
const validCloudContextOptions = ['aws'];

if (!validCloudContextOptions.includes(cloudContext)) {
throw new FlagValueError(
'cloud-context',
cloudContext,
validCloudContextOptions.join(', '),
);
}
}
2 changes: 2 additions & 0 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function prepareTestConfig(
const policy = await findAndLoadPolicy(process.cwd(), 'iac', options);
const scan = options.scan ?? 'resource-changes';
const varFile = options['var-file'];
const cloudContext = getFlag(options, 'cloud-context');

return {
paths,
Expand All @@ -78,6 +79,7 @@ async function prepareTestConfig(
scan,
varFile,
depthDetection,
cloudContext,
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/iac/test/v2/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ function processFlags(
flags.push('-var-file', options.varFile);
}

if (options.cloudContext) {
flags.push('-cloud-context', options.cloudContext);
}

return flags;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/iac/test/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface TestConfig {
scan: string;
varFile?: string;
depthDetection?: number;
cloudContext?: string;
}

0 comments on commit b46e07b

Please sign in to comment.