Skip to content

Commit e58bfee

Browse files
feat: extend HookStackProps from StackProps (#128)
* feat: extend `HookStackProps` from `StackProps` This allows the common "stack props" to be used during creation of this stack, as well as our custom `prune` value. * chore: `pnpm run changeset` --------- Co-authored-by: Sam Chung <[email protected]>
1 parent 9391a8a commit e58bfee

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.changeset/tired-islands-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-infra': minor
3+
---
4+
5+
HookStack: extend `HookStackProps` from `StackProps`

packages/infra/src/constructs/stack.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,27 @@ it('supports a custom ID', () => {
3434

3535
template.resourceCountIs('AWS::Lambda::Function', 2);
3636
});
37+
38+
describe('StackProps', () => {
39+
it('should use default values when none are provided', () => {
40+
const app = new App();
41+
42+
const defaultStack = new HookStack(app);
43+
expect(defaultStack.stackName).toBe('aws-codedeploy-hooks');
44+
expect(defaultStack.tags.hasTags()).toBeFalsy();
45+
});
46+
47+
it('should override the defaults when provided', () => {
48+
const app = new App();
49+
50+
const customStack = new HookStack(app, 'CustomStack', {
51+
stackName: 'custom',
52+
tags: { 'seek:custom:tag': 'value' },
53+
});
54+
expect(customStack.stackName).toBe('custom');
55+
expect(customStack.tags.hasTags()).toBeTruthy();
56+
expect(customStack.tags.tagValues()).toEqual({
57+
'seek:custom:tag': 'value',
58+
});
59+
});
60+
});

packages/infra/src/constructs/stack.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import { Stack, aws_iam, aws_lambda } from 'aws-cdk-lib';
1+
import { Stack, type StackProps, aws_iam, aws_lambda } from 'aws-cdk-lib';
22
import type { Construct } from 'constructs';
33

44
import { createLambdaHookProps } from './lambda';
55

66
type HookName = 'BeforeAllowTraffic' | 'AfterAllowTraffic';
77

8-
export type HookStackProps = {
8+
export type HookStackProps = StackProps & {
99
prune?: {
1010
versionsToKeep?: number;
1111
};
1212
};
1313

14+
const defaultProps: HookStackProps = {
15+
description: 'AWS CodeDeploy hooks',
16+
stackName: 'aws-codedeploy-hooks',
17+
terminationProtection: true,
18+
};
19+
1420
export class HookStack extends Stack {
1521
constructor(scope: Construct, id?: string, props: HookStackProps = {}) {
1622
super(scope, id ?? 'HookStack', {
17-
description: 'AWS CodeDeploy hooks',
18-
stackName: 'aws-codedeploy-hooks',
19-
terminationProtection: true,
23+
...defaultProps,
24+
...props,
2025
});
2126

2227
this.addHook('BeforeAllowTraffic', {}, ['lambda:InvokeFunction']);

0 commit comments

Comments
 (0)