Skip to content

Commit 089e9d8

Browse files
authored
fix(cli): cdk diff always falls back to template only diff (#32165)
Closes #32160 ### Reason for this change <!--What is the bug or use case behind this change?--> When running `cdk deploy`, it is supposed to (by default) create a read-only change set and incorporate it within the diff. However, it currently fails creating the change-set and always falls back to template only diffs. ### Description of changes <!--What code changes did you make? Have you made any important design decisions?--> There was a wrong invocation of the `makeBodyParameter` parameter after the [migration to sdk v3](#31702). ### Description of how you validated changes Added missing integration tests. Unit test for this code are tricky because they require too many mocks. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 740db43 commit 089e9d8

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js

+11
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,15 @@ class AppSyncHotswapStack extends cdk.Stack {
776776
}
777777
}
778778

779+
class MetadataStack extends cdk.Stack {
780+
constructor(parent, id, props) {
781+
super(parent, id, props);
782+
const handle = new cdk.CfnWaitConditionHandle(this, 'WaitConditionHandle');
783+
handle.addMetadata('Key', process.env.INTEG_METADATA_VALUE ?? 'default')
784+
785+
}
786+
}
787+
779788
const app = new cdk.App({
780789
context: {
781790
'@aws-cdk/core:assetHashSalt': process.env.CODEBUILD_BUILD_ID, // Force all assets to be unique, but consistent in one build
@@ -877,6 +886,8 @@ switch (stackSet) {
877886
new ExportValueStack(app, `${stackPrefix}-export-value-stack`);
878887

879888
new BundlingStage(app, `${stackPrefix}-bundling-stage`);
889+
890+
new MetadataStack(app, `${stackPrefix}-metadata`);
880891
break;
881892

882893
case 'stage-using-context':

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,46 @@ integTest(
10641064
}),
10651065
);
10661066

1067+
integTest(
1068+
'cdk diff doesnt show resource metadata changes',
1069+
withDefaultFixture(async (fixture) => {
1070+
1071+
// GIVEN - small initial stack with default resource metadata
1072+
await fixture.cdkDeploy('metadata');
1073+
1074+
// WHEN - changing resource metadata value
1075+
const diff = await fixture.cdk(['diff', fixture.fullStackName('metadata')], {
1076+
verbose: true,
1077+
modEnv: {
1078+
INTEG_METADATA_VALUE: 'custom',
1079+
},
1080+
});
1081+
1082+
// Assert there are no changes
1083+
expect(diff).toContain('There were no differences');
1084+
}),
1085+
);
1086+
1087+
integTest(
1088+
'cdk diff shows resource metadata changes with --no-change-set',
1089+
withDefaultFixture(async (fixture) => {
1090+
1091+
// GIVEN - small initial stack with default resource metadata
1092+
await fixture.cdkDeploy('metadata');
1093+
1094+
// WHEN - changing resource metadata value
1095+
const diff = await fixture.cdk(['diff --no-change-set', fixture.fullStackName('metadata')], {
1096+
verbose: true,
1097+
modEnv: {
1098+
INTEG_METADATA_VALUE: 'custom',
1099+
},
1100+
});
1101+
1102+
// Assert there are changes
1103+
expect(diff).not.toContain('There were no differences');
1104+
}),
1105+
);
1106+
10671107
integTest('cdk diff with large changeset and custom toolkit stack name and qualifier does not fail', withoutBootstrap(async (fixture) => {
10681108
// Bootstrapping with custom toolkit stack name and qualifier
10691109
const qualifier = 'abc1111';

packages/aws-cdk/lib/api/util/cloudformation.ts

-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ async function uploadBodyParameterAndCreateChangeSet(
400400
env.resolvedEnvironment,
401401
new AssetManifestBuilder(),
402402
env.resources,
403-
env.sdk,
404403
);
405404
const cfn = env.sdk.cloudFormation();
406405
const exists = (await CloudFormationStack.lookup(cfn, options.stack.stackName, false)).exists;

0 commit comments

Comments
 (0)