Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app-staging-synthesizer): option to specify staging stack name prefix #26324

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`);
}
});