Skip to content

Commit 7bc61d8

Browse files
authored
chore(cli): warn about a useless --force flag (#28150)
People expect the `--force` flag to do something that it doesn't do. Explicitly warn them about that behavior when it happens. Relates to #15065. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c54ac33 commit 7bc61d8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { StackActivityMonitor, StackActivityProgress } from './util/cloudformation/stack-activity-monitor';
1616
import { addMetadataAssetsToManifest } from '../assets';
1717
import { Tag } from '../cdk-toolkit';
18-
import { debug, error, print } from '../logging';
18+
import { debug, error, print, warning } from '../logging';
1919
import { toYAML } from '../serialize';
2020
import { AssetManifestBuilder } from '../util/asset-manifest-builder';
2121
import { publishAssets } from '../util/asset-publishing';
@@ -391,6 +391,17 @@ class FullCloudFormationDeployment {
391391
debug('Deleting empty change set %s', changeSetDescription.ChangeSetId);
392392
await this.cfn.deleteChangeSet({ StackName: this.stackName, ChangeSetName: changeSetName }).promise();
393393
}
394+
395+
if (this.options.force) {
396+
warning([
397+
'You used the --force flag, but CloudFormation reported that the deployment would not make any changes.',
398+
'According to CloudFormation, all resources are already up-to-date with the state in your CDK app.',
399+
'',
400+
'You cannot use the --force flag to get rid of changes you made in the console. Try using',
401+
'CloudFormation drift detection instead: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html',
402+
].join('\n'));
403+
}
404+
394405
return { noOp: true, outputs: this.cloudFormationStack.outputs, stackArn: changeSetDescription.StackId! };
395406
}
396407

0 commit comments

Comments
 (0)