Skip to content

Commit

Permalink
chore(cli): warn about a useless --force flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr committed Nov 27, 2023
1 parent 1a2481e commit e15d761
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { StackActivityMonitor, StackActivityProgress } from './util/cloudformation/stack-activity-monitor';
import { addMetadataAssetsToManifest } from '../assets';
import { Tag } from '../cdk-toolkit';
import { debug, error, print } from '../logging';
import { debug, error, print, warning } from '../logging';
import { toYAML } from '../serialize';
import { AssetManifestBuilder } from '../util/asset-manifest-builder';
import { publishAssets } from '../util/asset-publishing';
Expand Down Expand Up @@ -391,6 +391,17 @@ class FullCloudFormationDeployment {
debug('Deleting empty change set %s', changeSetDescription.ChangeSetId);
await this.cfn.deleteChangeSet({ StackName: this.stackName, ChangeSetName: changeSetName }).promise();
}

if (this.options.force) {
warning([
'You used the --force flag, but CloudFormation reported that the deployment would not make any changes.',
'According to CloudFormation, all resources are already up-to-date with the state in your CDK app.',
'',
'You cannot use the --force flag to get rid of changes you made in the console. Try using',
'CloudFormation drift detection instead: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html',
].join('\n'));
}

return { noOp: true, outputs: this.cloudFormationStack.outputs, stackArn: changeSetDescription.StackId! };
}

Expand Down

0 comments on commit e15d761

Please sign in to comment.