diff --git a/packages/@aws-cdk-testing/cli-integ/lib/index.ts b/packages/@aws-cdk-testing/cli-integ/lib/index.ts index cabb094e65c00..b5f7cd4548893 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/index.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/index.ts @@ -4,6 +4,7 @@ export * from './integ-test'; export * from './memoize'; export * from './resource-pool'; export * from './with-cli-lib'; +export * from './with-cli-lib-no-stacks'; export * from './with-sam'; export * from './shell'; export * from './with-aws'; diff --git a/packages/@aws-cdk-testing/cli-integ/lib/with-cli-no-stacks.ts b/packages/@aws-cdk-testing/cli-integ/lib/with-cli-lib-no-stacks.ts similarity index 96% rename from packages/@aws-cdk-testing/cli-integ/lib/with-cli-no-stacks.ts rename to packages/@aws-cdk-testing/cli-integ/lib/with-cli-lib-no-stacks.ts index 7d95eb9f1d41d..abf0096cad60d 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/with-cli-no-stacks.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/with-cli-lib-no-stacks.ts @@ -105,16 +105,18 @@ export class CliLibNoStacksIntegrationTestFixture extends TestFixture { */ public async cdk(args: string[], options: CdkCliOptions = {}) { const action = args[0]; - const stackName = args[1]; + const ignoreNoStacks = args[1]; - const cliOpts: Record = { - stacks: stackName ? [stackName] : undefined, - }; + const cliOpts: Record = {}; if (action === 'deploy') { cliOpts.requireApproval = options.neverRequireApproval ? 'never' : 'broadening'; } + if (ignoreNoStacks == '--ignore-no-stacks') { + cliOpts.ignoreNoStacks = true; + } + return this.shell(['node', '--input-type=module', `<<__EOS__ import { AwsCdkCli } from '@aws-cdk/cli-lib-alpha'; const cli = AwsCdkCli.fromCdkAppDirectory(); @@ -125,7 +127,6 @@ __EOS__`], { modEnv: { AWS_REGION: this.aws.region, AWS_DEFAULT_REGION: this.aws.region, - STACK_NAME_PREFIX: this.stackNamePrefix, PACKAGE_LAYOUT_VERSION: this.packages.majorVersion(), ...options.modEnv, }, diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js index 322b828baf3f1..eeb1ad83673e2 100755 --- a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js +++ b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js @@ -403,8 +403,6 @@ class BuiltinLambdaStack extends cdk.Stack { } } -class StackWithNoResources extends cdk.Stack {} - const app = new cdk.App({ context: { '@aws-cdk/core:assetHashSalt': process.env.CODEBUILD_BUILD_ID, // Force all assets to be unique, but consistent in one build @@ -494,8 +492,7 @@ switch (stackSet) { stage.synth({ validateOnSynthesis: true }); break; - case 'stage-with-no-resources': - new StackWithNoResources(app, `${stackPrefix}-stage-with-no-resources`); + case 'stage-with-no-stacks': break; default: diff --git a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/no-stack-app/app.js b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/no-stack-app/app.js index ff84c957c7397..0ab5ae37bbf1a 100755 --- a/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/no-stack-app/app.js +++ b/packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/no-stack-app/app.js @@ -1,11 +1,5 @@ const cdk = require('aws-cdk-lib/core'); -const stackPrefix = process.env.STACK_NAME_PREFIX; -if (!stackPrefix) { - throw new Error(`the STACK_NAME_PREFIX environment variable is required`); -} - const app = new cdk.App(); -new NoStackApp(app, `${stackPrefix}-no-stack-1`); app.synth(); diff --git a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli-lib.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli-lib.integtest.ts index c6d93177415db..2d0da77b48f63 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli-lib.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli-lib.integtest.ts @@ -1,4 +1,4 @@ -import { integTest, withCliLibFixture, withCliLibNoStacksFixture } from '../../lib'; +import { integTest, withCliLibFixture } from '../../lib'; jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime @@ -47,28 +47,6 @@ integTest('cli-lib deploy', withCliLibFixture(async (fixture) => { } })); -integTest('cli-lib deploy no stack', withCliLibNoStacksFixture(async (fixture) => { - const stackName = fixture.fullStackName('no-stack-1'); - - try { - // deploy the stack - await fixture.cdk(['deploy', stackName], { - options: ['--ignore-no-stacks'], - }); - - // verify the number of resources in the stack - const expectedStack = await fixture.aws.cloudFormation('describeStackResources', { - StackName: stackName, - }); - expect(expectedStack.StackResources?.length).toEqual(0); - } finally { - // delete the stack - await fixture.cdk(['destroy', stackName], { - captureStderr: false, - }); - } -})); - integTest('security related changes without a CLI are expected to fail when approval is required', withCliLibFixture(async (fixture) => { const stdErr = await fixture.cdk(['deploy', fixture.fullStackName('simple-1')], { onlyStderr: true, diff --git a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts index 1c00d9c9a7d19..ad6a5f6ed9ad2 100644 --- a/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts +++ b/packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts @@ -1,7 +1,7 @@ import { promises as fs, existsSync } from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { integTest, cloneDirectory, shell, withDefaultFixture, retry, sleep, randomInteger, withSamIntegrationFixture, RESOURCES_DIR, withCDKMigrateFixture } from '../../lib'; +import { integTest, cloneDirectory, shell, withDefaultFixture, retry, sleep, randomInteger, withSamIntegrationFixture, RESOURCES_DIR, withCDKMigrateFixture, withCliLibNoStacksFixture } from '../../lib'; jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime @@ -780,17 +780,22 @@ integTest('deploy stack without resource', withDefaultFixture(async (fixture) => .rejects.toThrow('conditional-resource does not exist'); })); -integTest('deploy --ignore-no-stacks', withDefaultFixture(async (fixture) => { - const stackArn = await fixture.cdkDeploy('stage-with-no-resources', { +integTest('deploy no stacks with --ignore-no-stacks', withDefaultFixture(async (fixture) => { + // empty array for stack names + await fixture.cdkDeploy([], { options: ['--ignore-no-stacks'], modEnv: { - INTEG_STACK_SET: 'stage-with-no-resources', + INTEG_STACK_SET: 'stage-with-no-stacks', }, }); +})); - // verify that we only deployed both stacks (there are 2 ARNs in the output) - /* eslint-disable no-console */ - console.log(stackArn); +integTest('deploy no stacks error', withDefaultFixture(async (fixture) => { + await expect(fixture.cdkDeploy([], { + modEnv: { + INTEG_STACK_SET: 'stage-with-no-stacks', + }, + })).rejects.toThrow('exited with error'); })); integTest('IAM diff', withDefaultFixture(async (fixture) => { diff --git a/packages/@aws-cdk/cdk-cli-wrapper/lib/cdk-wrapper.ts b/packages/@aws-cdk/cdk-cli-wrapper/lib/cdk-wrapper.ts index 9fe40b0b1314f..f8364c4a3f419 100644 --- a/packages/@aws-cdk/cdk-cli-wrapper/lib/cdk-wrapper.ts +++ b/packages/@aws-cdk/cdk-cli-wrapper/lib/cdk-wrapper.ts @@ -174,6 +174,7 @@ export class CdkCliWrapper implements ICdk { ...renderBooleanArg('previous-parameters', options.usePreviousParameters), ...renderBooleanArg('rollback', options.rollback), ...renderBooleanArg('staging', options.staging), + ...renderBooleanArg('ignore-no-stacks', options.ignoreNoStacks), ...options.reuseAssets ? renderArrayArg('--reuse-assets', options.reuseAssets) : [], ...options.notificationArns ? renderArrayArg('--notification-arns', options.notificationArns) : [], ...options.parameters ? renderMapArrayArg('--parameters', options.parameters) : [], diff --git a/packages/@aws-cdk/cdk-cli-wrapper/lib/commands/deploy.ts b/packages/@aws-cdk/cdk-cli-wrapper/lib/commands/deploy.ts index 59ffedefe9945..eb92f5ca0e37e 100644 --- a/packages/@aws-cdk/cdk-cli-wrapper/lib/commands/deploy.ts +++ b/packages/@aws-cdk/cdk-cli-wrapper/lib/commands/deploy.ts @@ -141,6 +141,13 @@ export interface DeployOptions extends DefaultCdkOptions { * @default 1 */ readonly concurrency?: number; + + /** + * Whether to deploy if the app contains no stacks. + * + * @default false + */ + readonly ignoreNoStacks?: boolean; } export type DeploymentMethod = 'direct' | 'change-set'; diff --git a/packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts b/packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts index 266a7b9c81190..d370d5fd295ce 100644 --- a/packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts +++ b/packages/@aws-cdk/cdk-cli-wrapper/test/cdk-wrapper.test.ts @@ -89,6 +89,7 @@ test('deploy with all arguments', () => { versionReporting: true, usePreviousParameters: true, progress: StackActivityProgress.BAR, + ignoreNoStacks: true, }); // THEN @@ -129,6 +130,7 @@ test('deploy with all arguments', () => { '--previous-parameters', '--progress', 'bar', '--app', + '--ignore-no-stacks', 'node bin/my-app.js', 'test-stack1', ]), diff --git a/packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES b/packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES index 9927af86bd644..c430595bb0514 100644 --- a/packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES +++ b/packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES @@ -207,7 +207,7 @@ The @aws-cdk/cli-lib-alpha package includes the following third-party software/l ---------------- -** @jsii/check-node@1.92.0 - https://www.npmjs.com/package/@jsii/check-node/v/1.92.0 | Apache-2.0 +** @jsii/check-node@1.93.0 - https://www.npmjs.com/package/@jsii/check-node/v/1.93.0 | Apache-2.0 jsii Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -471,7 +471,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH RE ---------------- -** aws-sdk@2.1498.0 - https://www.npmjs.com/package/aws-sdk/v/2.1498.0 | Apache-2.0 +** aws-sdk@2.1517.0 - https://www.npmjs.com/package/aws-sdk/v/2.1517.0 | Apache-2.0 AWS SDK for JavaScript Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. @@ -668,7 +668,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ---------------- -** cdk-from-cfn@0.84.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.84.0 | MIT OR Apache-2.0 +** cdk-from-cfn@0.91.0 - https://www.npmjs.com/package/cdk-from-cfn/v/0.91.0 | MIT OR Apache-2.0 ---------------- diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index c4dcf03c5b1ef..122e51c7853c0 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -126,7 +126,7 @@ export interface DeployStackOptions { * The collection of extra parameters * (in addition to those used for assets) * to pass to the deployed template. - * Note that parameters with `undefined` or empty values will be ignored, + * Note that parameters with `undefined` or empty values will be d, * and not passed to the template. * * @default - no additional parameters will be passed to the template @@ -205,13 +205,6 @@ export interface DeployStackOptions { * @default true To remain backward compatible. */ readonly assetParallelism?: boolean; - - /** - * Whether to deploy if the app contains no stacks. - * - * @default false - */ - ignoreNoStacks?: boolean; } export type DeploymentMethod =