Skip to content

Commit 97cc8e2

Browse files
authored
fix(aws-cdk): include nested stacks when building changesets (#19494)
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*
1 parent 94f9d27 commit 97cc8e2

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

packages/aws-cdk/lib/api/deploy-stack.ts

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ async function prepareAndExecuteChangeSet(
299299
StackName: deployName,
300300
ChangeSetName: changeSetName,
301301
ChangeSetType: update ? 'UPDATE' : 'CREATE',
302+
IncludeNestedStacks: true,
302303
Description: `CDK Changeset for execution ${executionId}`,
303304
TemplateBody: bodyParameter.TemplateBody,
304305
TemplateURL: bodyParameter.TemplateURL,

packages/aws-cdk/test/api/deploy-stack.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ test('correctly passes CFN parameters, ignoring ones with empty values', async (
164164
}));
165165
});
166166

167+
test('correctly passes IncludeNestedStacks', async () => {
168+
// WHEN
169+
await deployStack({
170+
...standardDeployStackArguments(),
171+
});
172+
173+
// THEN
174+
expect(cfnMocks.createChangeSet).toHaveBeenCalledWith(expect.objectContaining({
175+
IncludeNestedStacks: true,
176+
}));
177+
});
178+
167179
test('reuse previous parameters if requested', async () => {
168180
// GIVEN
169181
givenStackExists({

packages/aws-cdk/test/integ/cli/cli.integtest.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,13 @@ integTest('fast deploy', withDefaultFixture(async (fixture) => {
638638
const changeSet2 = await getLatestChangeSet();
639639
expect(changeSet2.ChangeSetId).toEqual(changeSet1.ChangeSetId);
640640

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

646649
// Deploy the stack again with tags, expected to create a new changeset
647650
// even though the resources didn't change.

packages/aws-cdk/test/integ/helpers/cdk.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,9 @@ export async function installNpmPackages(fixture: TestFixture, packages: Record<
720720
const installNpm7 = memoize0(async (): Promise<string> => {
721721
const installDir = path.join(os.tmpdir(), 'cdk-integ-npm7');
722722
await shell(['rm', '-rf', installDir]);
723-
await shell(['mkdir', '-p', installDir]);
723+
await shell(['mkdir', '-p', `${installDir}/node_modules`]);
724724

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

729727
return path.join(installDir, 'node_modules', '.bin', 'npm');
730728
});

0 commit comments

Comments
 (0)