Skip to content

Commit

Permalink
fix: terraform plan scan to include data input
Browse files Browse the repository at this point in the history
  • Loading branch information
rontalx committed Mar 10, 2021
1 parent a6b6c37 commit 0232923
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ function terraformPlanReducer(
resource: TerraformPlanResource,
): TerraformScanInput {
// TODO: investigate if this reduction logic covers all edge-cases (nested modules, similar names, etc')
const { type, name } = resource;
if (scanInput.resource[resource.type]) {
const { type, name, mode, index, values } = resource;
const inputKey: keyof TerraformScanInput =
mode === 'data' ? 'data' : 'resource';
if (scanInput[inputKey][type]) {
// add new resources of the same type with different names
scanInput.resource[type][
resource.index !== undefined
? `${resource.name}_${resource.index}`
: resource.name
] = resource.values || {};
scanInput[inputKey][type][index !== undefined ? `${name}_${index}` : name] =
values || {};
} else {
// add a new resource type
scanInput.resource[type] = { [name]: resource.values };
scanInput[inputKey][type] = { [name]: values };
}

return scanInput;
Expand Down Expand Up @@ -59,7 +58,7 @@ export function tryParsingTerraformPlan(
const parsedInput = [
...rootModuleResources,
...childModuleResources,
].reduce(terraformPlanReducer, { resource: {} });
].reduce(terraformPlanReducer, { resource: {}, data: {} });
return [
{
...terraformPlanFile,
Expand Down
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 @@ -97,6 +97,7 @@ export interface TerraformPlanJson {
export interface TerraformScanInput {
// within the resource field, resources are stored: [type] => [name] => [values]
resource: Record<string, Record<string, unknown>>;
data: Record<string, Record<string, unknown>>;
}

export interface TerraformPlanResource {
Expand Down

0 comments on commit 0232923

Please sign in to comment.