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 1 commit
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
Next Next commit
feat(app-staging-synthesizer): option to specify staging stack name p…
…refix
  • Loading branch information
kaizencc committed Jul 11, 2023
commit 841a3194f85f5e9cb1fccdb453e3ba4eecb8414d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`);
}
});