From 67972580ab7258aa0829c00120083850b8ce6ffd Mon Sep 17 00:00:00 2001 From: Sami Turcotte Date: Fri, 12 Feb 2021 18:36:42 -0500 Subject: [PATCH 1/2] Reintroduce --change-set-name CLI flag --- packages/aws-cdk/README.md | 7 +- packages/aws-cdk/bin/cdk.ts | 2 + .../lib/api/cloudformation-deployments.ts | 155 +++++++++++++----- packages/aws-cdk/lib/api/deploy-stack.ts | 28 ++-- packages/aws-cdk/lib/cdk-toolkit.ts | 7 + .../aws-cdk/test/integ/cli/cli.integtest.ts | 15 +- 6 files changed, 156 insertions(+), 58 deletions(-) diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 78e2177b186cd..71b05cc420eac 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -288,13 +288,14 @@ The `progress` key can also be specified as a user setting (`~/.cdk.json`) #### Externally Executable CloudFormation Change Sets For more control over when stack changes are deployed, the CDK can generate a -CloudFormation change set but not execute it. The name of the generated +CloudFormation change set but not execute it. The default name of the generated change set is *cdk-deploy-change-set*, and a previous change set with that name will be overwritten. The change set will always be created, even if it -is empty. +is empty. A name can also be given to the change set to make it easier to later +execute. ```console -$ cdk deploy --no-execute +$ cdk deploy --no-execute --change-set-name MyChangeSetName ``` ### `cdk destroy` diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 707c4ab770758..9dc3a71799457 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -94,6 +94,7 @@ async function parseCommandLineArguments() { // @deprecated(v2) -- tags are part of the Cloud Assembly and tags specified here will be overwritten on the next deployment .option('tags', { type: 'array', alias: 't', desc: 'Tags to add to the stack (KEY=VALUE), overrides tags from Cloud Assembly (deprecated)', nargs: 1, requiresArg: true }) .option('execute', { type: 'boolean', desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)', default: true }) + .option('change-set-name', { type: 'string', desc: 'Name of the CloudFormation change set to create' }) .option('force', { alias: 'f', type: 'boolean', desc: 'Always deploy stack even if templates are identical', default: false }) .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {} }) .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true }) @@ -316,6 +317,7 @@ async function initCommandLine() { reuseAssets: args['build-exclude'], tags: configuration.settings.get(['tags']), execute: args.execute, + changeSetName: args.changeSetName, force: args.force, parameters: parameterMap, usePreviousParameters: args['previous-parameters'], diff --git a/packages/aws-cdk/lib/api/cloudformation-deployments.ts b/packages/aws-cdk/lib/api/cloudformation-deployments.ts index 3fe5fed118a76..2d98dd358338c 100644 --- a/packages/aws-cdk/lib/api/cloudformation-deployments.ts +++ b/packages/aws-cdk/lib/api/cloudformation-deployments.ts @@ -1,13 +1,13 @@ -import * as cxapi from '@aws-cdk/cx-api'; -import { AssetManifest } from 'cdk-assets'; -import { Tag } from '../cdk-toolkit'; -import { debug } from '../logging'; -import { publishAssets } from '../util/asset-publishing'; -import { Mode, SdkProvider } from './aws-auth'; -import { deployStack, DeployStackResult, destroyStack } from './deploy-stack'; -import { ToolkitInfo } from './toolkit-info'; -import { CloudFormationStack, Template } from './util/cloudformation'; -import { StackActivityProgress } from './util/cloudformation/stack-activity-monitor'; +import * as cxapi from "@aws-cdk/cx-api"; +import { AssetManifest } from "cdk-assets"; +import { Tag } from "../cdk-toolkit"; +import { debug } from "../logging"; +import { publishAssets } from "../util/asset-publishing"; +import { Mode, SdkProvider } from "./aws-auth"; +import { deployStack, DeployStackResult, destroyStack } from "./deploy-stack"; +import { ToolkitInfo } from "./toolkit-info"; +import { CloudFormationStack, Template } from "./util/cloudformation"; +import { StackActivityProgress } from "./util/cloudformation/stack-activity-monitor"; export interface DeployStackOptions { /** @@ -69,6 +69,12 @@ export interface DeployStackOptions { */ execute?: boolean; + /** + * Optional name to use for the CloudFormation change set. + * If not provided, a name will be generated automatically. + */ + changeSetName?: string; + /** * Force deployment, even if the deployed template is identical to the one we are about to deploy. * @default false deployment will be skipped if the template is identical @@ -136,19 +142,38 @@ export class CloudFormationDeployments { this.sdkProvider = props.sdkProvider; } - public async readCurrentTemplate(stackArtifact: cxapi.CloudFormationStackArtifact): Promise