Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions packages/@aws-cdk/toolkit-lib/lib/payloads/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CloudFormationStackArtifact } from '@aws-cdk/cx-api';
import type { IManifestEntry } from 'cdk-assets';
import type { PermissionChangeType } from './diff';
import type { ConfirmationRequest } from './types';
import { TemplateDiff } from '@aws-cdk/cloudformation-diff';

// re-export so they are part of the public API
export { DeployStackResult, SuccessfulDeployStackResult, NeedRollbackFirstDeployStackResult, ReplacementRequiresRollbackStackResult } from '../api/deployments/deployment-result';
Expand Down Expand Up @@ -32,6 +33,11 @@ export interface DeployConfirmationRequest extends ConfirmationRequest {
* The type of change being made to the IAM permissions.
*/
readonly permissionChangeType: PermissionChangeType;

/**
* The template diffs of the stack
*/
readonly templateDiffs: { [name: string]: TemplateDiff };
}

export interface BuildAsset {
Expand Down
12 changes: 9 additions & 3 deletions packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,19 @@ export class Toolkit extends CloudAssemblySourceBuilder {
});

const securityDiff = formatter.formatSecurityDiff();
const permissionChangeType = securityDiff.permissionChangeType;

console.log('diffs', JSON.stringify(formatter.diffs));

// Send a request response with the formatted security diff as part of the message,
// and the template diff as data
// (IoHost decides whether to print depending on permissionChangeType)
const deployMotivation = '"--require-approval" is enabled and stack includes security-sensitive updates.';
const deployQuestion = `${deployMotivation}\nDo you wish to deploy these changes`;
const deployQuestion = `${securityDiff.formattedDiff}\n\n${deployMotivation}\nDo you wish to deploy these changes`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't have a good way of testing this because formatted diff has a bunch of bold/underlined/colored words so it's hard to unit test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run stripAnsi over it

const deployConfirmed = await ioHelper.requestResponse(IO.CDK_TOOLKIT_I5060.req(deployQuestion, {
motivation: deployMotivation,
concurrency,
permissionChangeType,
permissionChangeType: securityDiff.permissionChangeType,
templateDiffs: formatter.diffs,
}));
if (!deployConfirmed) {
throw new ToolkitError('Aborted by user');
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/toolkit-lib/test/actions/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ describe('deploy', () => {
data: expect.objectContaining({
motivation: expect.stringContaining('stack includes security-sensitive updates.'),
permissionChangeType: 'broadening',
templateDiffs: expect.objectContaining({
Stack1: expect.objectContaining({
resources: expect.objectContaining({
diffs: expect.objectContaining({
Role1ABCC5F0: expect.objectContaining({
newValue: expect.objectContaining({
Type: 'AWS::IAM::Role',
Properties: expect.anything(),
}),
}),
}),
}),
}),
}),
}),
}));
});
Expand Down
Loading