Skip to content

Commit

Permalink
feat(app-staging-synthesizer): option to specify staging stack name p…
Browse files Browse the repository at this point in the history
…refix (#26324)

Optionally specify a prefix for the staging stack name, which will be baked into the stackId and stackName. The default prefix is `StagingStack`. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Jul 21, 2023
1 parent fd181c7 commit 1b36124
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export interface DefaultStagingStackOptions {
* @default true
*/
readonly autoDeleteStagingAssets?: boolean;

/**
* 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'
*/
readonly stagingStackNamePrefix?: string;
}

/**
Expand Down Expand Up @@ -159,12 +169,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,29 @@ describe(AppStagingSynthesizer, () => {
Template.fromJSON(getStagingResourceStack(asm).template).resourceCountIs('Custom::S3AutoDeleteObjects', 0);
});

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
Expand Down Expand Up @@ -536,7 +559,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`);
}
});

0 comments on commit 1b36124

Please sign in to comment.