From c02c9e5518bfb2d8f8195322b7fd97343f5ca63b Mon Sep 17 00:00:00 2001 From: robertma96 <37088728+robertma96@users.noreply.github.com> Date: Wed, 13 Nov 2019 13:57:33 +0200 Subject: [PATCH] feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed (#4852) * feat(aws-cdk): adding new option to `cdk deploy` I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 * feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 * feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 * feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 * feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 * feat(cli): adding new option to `cdk deploy` to indicate whether ChangeSet should be executed I created the option to *NOT* execute the ChangeSet via `cdk deploy`. The flag is called **execute** and by default is set to true. By not providing this flag, the workflow of `cdk deploy` will be the same. If anyone wants to *NOT* execute the ChangeSet, providing the flag `--no-execute` will pass the execution of the ChangeSet. You will be able to see the ChangeSet in AWS CloudFormation Console, validate the resources and discard or execute the ChangeSet. closes #4739 --- packages/aws-cdk/bin/cdk.ts | 2 ++ packages/aws-cdk/lib/api/deploy-stack.ts | 24 +++++++++++------ packages/aws-cdk/lib/api/deployment-target.ts | 4 ++- packages/aws-cdk/lib/cdk-toolkit.ts | 10 ++++++- .../integ/cli/test-cdk-deploy-no-execute.sh | 27 +++++++++++++++++++ 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100755 packages/aws-cdk/test/integ/cli/test-cdk-deploy-no-execute.sh diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index ab3ec36ca5b48..61b47fe3c6368 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -59,6 +59,7 @@ async function parseCommandLineArguments() { .option('ci', { type: 'boolean', desc: 'Force CI detection. Use --no-ci to disable CI autodetection.', default: process.env.CI !== undefined }) .option('notification-arns', {type: 'array', desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events', nargs: 1, requiresArg: true}) .option('tags', { type: 'array', alias: 't', desc: 'Tags to add to the stack (KEY=VALUE)', nargs: 1, requiresArg: true })) + .option('execute', {type: 'boolean', desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)', default: true}) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only deploy requested stacks, don\'t include dependees' }) .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' })) @@ -207,6 +208,7 @@ async function initCommandLine() { reuseAssets: args['build-exclude'], tags: configuration.settings.get(['tags']), sdk: aws, + execute: args.execute }); case 'destroy': diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index dcc1cc739b3f2..dbd261cee60e2 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -37,6 +37,7 @@ export interface DeployStackOptions { ci?: boolean; reuseAssets?: string[]; tags?: Tag[]; + execute?: boolean; } const LARGE_TEMPLATE_SIZE_KB = 50; @@ -92,14 +93,21 @@ export async function deployStack(options: DeployStackOptions): Promise ${response_json} + +stack_status=$(node -e "console.log(require('${response_json}').Stacks[0].StackStatus)") +if [ "${stack_status}" -ne "REVIEW_IN_PROGRESS" ]; then + fail "Expected stack to be in status REVIEW_IN_PROGRESS but got ${stack_status}" +fi + +# destroy +cdk destroy -f ${STACK_NAME_PREFIX}-test-2 + +echo "✅ success"