Skip to content

Commit

Permalink
moved defaulting logic to deploy-stack.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
comcalvi committed Sep 2, 2021
1 parent 5be50b1 commit bad64f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function parseCommandLineArguments() {
.option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true })
.option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' })
.option('progress', { type: 'string', choices: [StackActivityProgress.BAR, StackActivityProgress.EVENTS], desc: 'Display mode for stack activity events' })
.option('rollback', { type: 'boolean', default: undefined, desc: 'Rollback stack to stable state on failure (iterate more rapidly with --no-rollback or -R)' })
.option('rollback', { type: 'boolean', desc: 'Rollback stack to stable state on failure (iterate more rapidly with --no-rollback or -R)' })
// Hack to get '-R' as an alias for '--no-rollback', suggested by: https://github.com/yargs/yargs/issues/1729
.option('R', { type: 'boolean', hidden: true })
.middleware(yargsNegativeAlias('R', 'rollback'), true)
Expand All @@ -115,8 +115,7 @@ async function parseCommandLineArguments() {
'which skips CloudFormation and updates the resources directly, ' +
'and falls back to a full deployment if that is not possible. ' +
'Do not use this in production environments',
})
.option('progress', { type: 'string', choices: [StackActivityProgress.BAR, StackActivityProgress.EVENTS], desc: 'Display mode for stack activity events' }),
}),
)
.command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs
.option('all', { type: 'boolean', default: false, desc: 'Destroy all available stacks' })
Expand Down
14 changes: 5 additions & 9 deletions packages/aws-cdk/lib/api/deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export interface DeployStackOptions {
*
* @default true
*/
readonly rollback?: boolean;
rollback?: boolean;

/*
* Whether to perform a 'hotswap' deployment.
Expand Down Expand Up @@ -250,6 +250,9 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt

await publishAssets(legacyAssets.toManifest(stackArtifact.assembly.directory), options.sdkProvider, stackEnv);

const shouldDisableRollback = (options.rollback === undefined && options.hotswap === true) || options.rollback === false;
options.rollback = shouldDisableRollback ? false : true;

if (options.hotswap) {
// attempt to short-circuit the deployment if possible
const hotswapDeploymentResult = await tryHotswapDeployment(options.sdkProvider, assetParams, cloudFormationStack, stackArtifact);
Expand Down Expand Up @@ -326,14 +329,7 @@ async function prepareAndExecuteChangeSet(

// Do a bit of contortions to only pass the `DisableRollback` flag if it's true. That way,
// CloudFormation won't balk at the unrecognized option in regions where the feature is not available yet.
let disableRollback;

if (options.rollback === undefined && options.hotswap === true) {
disableRollback = { DisableRollback: true };
} else {
disableRollback = options.rollback === false ? { DisableRollback: true } : undefined;
}

const disableRollback = options.rollback === false ? { DisableRollback: true } : undefined;
await cfn.executeChangeSet({ StackName: deployName, ChangeSetName: changeSetName, ...disableRollback }).promise();

// eslint-disable-next-line max-len
Expand Down

0 comments on commit bad64f4

Please sign in to comment.