Skip to content

Commit

Permalink
fix(cli): --hotswap does not handle CfnOutput change correctly (#…
Browse files Browse the repository at this point in the history
…21461)

closes #19998

Although there are other types of diffs (other than `outputs`) that are currently ignored by hotswap, I leave them as-is since no one is complaining about the behavior and it may break someone's hotswap experience.

https://github.com/aws/aws-cdk/blob/3853728c699bd9c47b60fcc24ac6a8b7d65306fe/packages/%40aws-cdk/cloudformation-diff/lib/diff/types.ts#L10-L21

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
tmokmss authored Aug 4, 2022
1 parent e9233fa commit 7ccc644
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/aws-cdk/lib/api/hotswap-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ async function findAllHotswappableChanges(
sdk: ISDK,
nestedStackNames: { [nestedStackName: string]: NestedStackNames },
): Promise<HotswapOperation[] | undefined> {
// Skip hotswap if there is any change on stack outputs
if (stackChanges.outputs.differenceCount > 0) {
return undefined;
}

const resourceDifferences = getStackResourceDifferences(stackChanges);

let foundNonHotswappableChange = false;
Expand Down
58 changes: 58 additions & 0 deletions packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,61 @@ test('changing the type of a deployed resource always results in a full deployme
expect(mockUpdateMachineDefinition).not.toHaveBeenCalled();
expect(mockUpdateLambdaCode).not.toHaveBeenCalled();
});

test('A change to both a hotswappable resource and a stack output results in a full deployment', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Func: {
Type: 'AWS::Lambda::Function',
Properties: {
Code: {
S3Bucket: 'current-bucket',
S3Key: 'current-key',
},
FunctionName: 'my-function',
},
Metadata: {
'aws:asset:path': 'old-path',
},
},
},
Outputs: {
SomeOutput: {
Value: 'old-value',
},
},
});
const cdkStackArtifact = setup.cdkStackArtifactOf({
template: {
Resources: {
Func: {
Type: 'AWS::Lambda::Function',
Properties: {
Code: {
S3Bucket: 'current-bucket',
S3Key: 'new-key',
},
FunctionName: 'my-function',
},
Metadata: {
'aws:asset:path': 'new-path',
},
},
},
Outputs: {
SomeOutput: {
Value: 'new-value',
},
},
},
});

// WHEN
const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(cdkStackArtifact);

// THEN
expect(deployStackResult).toBeUndefined();
expect(mockUpdateMachineDefinition).not.toHaveBeenCalled();
expect(mockUpdateLambdaCode).not.toHaveBeenCalled();
});

0 comments on commit 7ccc644

Please sign in to comment.