Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 2 deletions packages/@aws-cdk/toolkit-lib/lib/actions/drift/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { StackSelector } from '../../api/cloud-assembly';

export interface DriftOptions {
/**
* Criteria for selecting stacks to check for drift
* Select stacks to check for drift
*
* @default - all stacks
*/
readonly stacks: StackSelector;
readonly stacks?: StackSelector;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
/**
* Drift Action
*/
public async drift(cx: ICloudAssemblySource, options: DriftOptions): Promise<{ [name: string]: DriftResult }> {
public async drift(cx: ICloudAssemblySource, options: DriftOptions = {}): Promise<{ [name: string]: DriftResult }> {
const ioHelper = asIoHelper(this.ioHost, 'drift');
const selectStacks = options.stacks ?? ALL_STACKS;
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: selectStacks });
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/toolkit-lib/test/actions/drift.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,19 @@ describe('drift', () => {
ioHost.expectMessage({ containing: 'Modified Resources', level: 'info' });
ioHost.expectMessage({ containing: '[~] AWS::S3::Bucket MyBucket MyBucketF68F3FF0', level: 'info' });
});

test('can invoke drift action without options', async () => {
// GIVEN
mockCloudFormationClient.on(DetectStackDriftCommand).resolves({ StackDriftDetectionId: '12345' });
mockCloudFormationClient.on(DescribeStackDriftDetectionStatusCommand).resolves({ DetectionStatus: 'DETECTION_COMPLETE' });
mockCloudFormationClient.on(DescribeStackResourceDriftsCommand).resolvesOnce({});

// WHEN
const cx = await builderFixture(toolkit, 'stack-with-bucket');
const result = await toolkit.drift(cx);

// THEN
expect(Object.keys(result).length).toBe(0);
ioHost.expectMessage({ containing: 'No drift results available' });
});
});