Skip to content

Commit

Permalink
fix(aws-cdk): include nested stacks when building changesets (#19494)
Browse files Browse the repository at this point in the history
This is a workaround for #5722 - users can do `cdk deploy --no-execute`
and then view the nested changesets as a way to get a full diff of
changes.

This PR is a re-roll of #17396. That PR broke an integration test in the CLI,
which this version fixes.

Closes #19224.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Mar 29, 2022
1 parent 94f9d27 commit 97cc8e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ async function prepareAndExecuteChangeSet(
StackName: deployName,
ChangeSetName: changeSetName,
ChangeSetType: update ? 'UPDATE' : 'CREATE',
IncludeNestedStacks: true,
Description: `CDK Changeset for execution ${executionId}`,
TemplateBody: bodyParameter.TemplateBody,
TemplateURL: bodyParameter.TemplateURL,
Expand Down
12 changes: 12 additions & 0 deletions packages/aws-cdk/test/api/deploy-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ test('correctly passes CFN parameters, ignoring ones with empty values', async (
}));
});

test('correctly passes IncludeNestedStacks', async () => {
// WHEN
await deployStack({
...standardDeployStackArguments(),
});

// THEN
expect(cfnMocks.createChangeSet).toHaveBeenCalledWith(expect.objectContaining({
IncludeNestedStacks: true,
}));
});

test('reuse previous parameters if requested', async () => {
// GIVEN
givenStackExists({
Expand Down
9 changes: 6 additions & 3 deletions packages/aws-cdk/test/integ/cli/cli.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,13 @@ integTest('fast deploy', withDefaultFixture(async (fixture) => {
const changeSet2 = await getLatestChangeSet();
expect(changeSet2.ChangeSetId).toEqual(changeSet1.ChangeSetId);

// Deploy the stack again with --force, now we should create a changeset
await fixture.cdkDeploy('with-nested-stack', { options: ['--force'] });
// Deploy the stack again with --force. This creates a changeset which will be
// empty (since CFN now tracks changes into nested stacks as well), so we delete
// it again because it couldn't be executed anyway.
const output = await fixture.cdkDeploy('with-nested-stack', { options: ['--force'] });
const changeSet3 = await getLatestChangeSet();
expect(changeSet3.ChangeSetId).not.toEqual(changeSet2.ChangeSetId);
expect(output).toContain('No changes are to be performed on');
expect(changeSet3.ChangeSetId).toEqual(changeSet2.ChangeSetId);

// Deploy the stack again with tags, expected to create a new changeset
// even though the resources didn't change.
Expand Down
6 changes: 2 additions & 4 deletions packages/aws-cdk/test/integ/helpers/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,9 @@ export async function installNpmPackages(fixture: TestFixture, packages: Record<
const installNpm7 = memoize0(async (): Promise<string> => {
const installDir = path.join(os.tmpdir(), 'cdk-integ-npm7');
await shell(['rm', '-rf', installDir]);
await shell(['mkdir', '-p', installDir]);
await shell(['mkdir', '-p', `${installDir}/node_modules`]);

await shell(['npm', 'install',
'--prefix', installDir,
'npm@7']);
await shell(['npm', 'install', 'npm@7'], { cwd: installDir });

return path.join(installDir, 'node_modules', '.bin', 'npm');
});
Expand Down

0 comments on commit 97cc8e2

Please sign in to comment.