Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): direct deploy method fails when there are no updates #28523

Merged
merged 2 commits into from
Jan 3, 2024
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
26 changes: 17 additions & 9 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,24 @@ class FullCloudFormationDeployment {
const startTime = new Date();

if (this.update) {
await this.cfn.updateStack({
StackName: this.stackName,
ClientRequestToken: `update${this.uuid}`,
...this.commonPrepareOptions(),
...this.commonExecuteOptions(),
}).promise();

const ret = await this.monitorDeployment(startTime, undefined);
await this.updateTerminationProtection();
return ret;

try {
await this.cfn.updateStack({
StackName: this.stackName,
ClientRequestToken: `update${this.uuid}`,
...this.commonPrepareOptions(),
...this.commonExecuteOptions(),
}).promise();
} catch (err: any) {
if (err.message === 'No updates are to be performed.') {
debug('No updates are to be performed for stack %s', this.stackName);
return { noOp: true, outputs: this.cloudFormationStack.outputs, stackArn: this.cloudFormationStack.stackId };
}
throw err;
}

return this.monitorDeployment(startTime, undefined);
} else {
// Take advantage of the fact that we can set termination protection during create
const terminationProtection = this.stackArtifact.terminationProtection ?? false;
Expand Down
19 changes: 19 additions & 0 deletions packages/aws-cdk/test/api/deploy-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ test('call UpdateStack when method=direct and the stack exists already', async (
expect(cfnMocks.updateStack).toHaveBeenCalled();
});

test('method=direct and no updates to be performed', async () => {
cfnMocks.updateStack?.mockRejectedValueOnce({
code: 'ValidationError',
message: 'No updates are to be performed.',
} as never);

// WHEN
givenStackExists();

const ret = await deployStack({
...standardDeployStackArguments(),
deploymentMethod: { method: 'direct' },
force: true,
});

// THEN
expect(ret).toEqual(expect.objectContaining({ noOp: true }));
});

test("does not call tryHotswapDeployment() if 'hotswap' is false", async () => {
// WHEN
await deployStack({
Expand Down
Loading