From 841a3194f85f5e9cb1fccdb453e3ba4eecb8414d Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 11 Jul 2023 14:55:37 -0400 Subject: [PATCH 1/2] feat(app-staging-synthesizer): option to specify staging stack name prefix --- .../lib/default-staging-stack.ts | 18 ++++++++++--- .../test/app-staging-synthesizer.test.ts | 27 +++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts b/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts index be3a44eb15fd3..409dd513da0b3 100644 --- a/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts +++ b/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts @@ -111,6 +111,15 @@ export interface DefaultStagingStackOptions { * @default true */ readonly autoDeleteStagingAssets?: boolean; + + /** + * The name to deploy the stack with. The prefix will be appended + * before the appId, which is required to be part of the stack name + * to ensure uniqueness. + * + * @default 'StagingStack' + */ + readonly stagingStackNamePrefix?: string; } /** @@ -159,12 +168,13 @@ export class DefaultStagingStack extends Stack implements IStagingResources { new UsingAppStagingSynthesizer(stack, `UsingAppStagingSynthesizer/${stack.stackName}`); } - const stackId = `StagingStack-${appId}-${context.environmentString}`; + const stackPrefix = options.stagingStackNamePrefix ?? 'StagingStack'; + // Stack name does not need to contain environment because appId is unique inside an env + const stackName = `${stackPrefix}-${appId}`; + const stackId = `${stackName}-${context.environmentString}`; return new DefaultStagingStack(app, stackId, { ...options, - - // Does not need to contain environment because stack names are unique inside an env anyway - stackName: `StagingStack-${appId}`, + stackName, env: { account: stack.account, region: stack.region, diff --git a/packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts b/packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts index f71114c2888c6..1b3cf2723282d 100644 --- a/packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts +++ b/packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts @@ -462,6 +462,29 @@ describe(AppStagingSynthesizer, () => { }); }); + test('stack prefix can be customized', () => { + // GIVEN + const prefix = 'Prefix'; + app = new App({ + defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({ + appId: APP_ID, + stagingStackNamePrefix: prefix, + }), + }); + stack = new Stack(app, 'Stack', { + env: { + account: '000000000000', + region: 'us-east-1', + }, + }); + + // WHEN + const asm = app.synth(); + + // THEN + expect(getStagingResourceStack(asm, prefix).template).toBeDefined(); + }); + describe('environment specifics', () => { test('throws if App includes env-agnostic and specific env stacks', () => { // GIVEN - App with Stack with specific environment @@ -506,7 +529,7 @@ describe(AppStagingSynthesizer, () => { /** * Return the staging resource stack that is generated as part of the assembly */ - function getStagingResourceStack(asm: CloudAssembly) { - return asm.getStackArtifact(`StagingStack-${APP_ID}-000000000000-us-east-1`); + function getStagingResourceStack(asm: CloudAssembly, prefix?: string) { + return asm.getStackArtifact(`${prefix ?? 'StagingStack'}-${APP_ID}-000000000000-us-east-1`); } }); From fbbecaf9391e5c5812ec225a35be3955004116bd Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 11 Jul 2023 14:58:35 -0400 Subject: [PATCH 2/2] docs --- .../lib/default-staging-stack.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts b/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts index 409dd513da0b3..6875de6a123d2 100644 --- a/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts +++ b/packages/@aws-cdk/app-staging-synthesizer-alpha/lib/default-staging-stack.ts @@ -113,9 +113,10 @@ export interface DefaultStagingStackOptions { readonly autoDeleteStagingAssets?: boolean; /** - * The name to deploy the stack with. The prefix will be appended - * before the appId, which is required to be part of the stack name - * to ensure uniqueness. + * Specify a custom prefix to be used as the staging stack name and + * construct ID. The prefix will be appended before the appId, which + * is required to be part of the stack name and construct ID to + * ensure uniqueness. * * @default 'StagingStack' */