| | | 1 | | import { Stack, type StackProps, Tags } from "aws-cdk-lib"; |
| | | 2 | | import type { Construct } from "constructs"; |
| | | 3 | | import type { AppEnvironment } from "../core/types"; |
| | | 4 | | import { formatRepoNameForCloudFormation } from "./utils"; |
| | | 5 | | |
| | | 6 | | export interface DomainConfig { |
| | | 7 | | subdomain?: string; |
| | | 8 | | domainName: string; |
| | | 9 | | hostedZoneId: string; |
| | | 10 | | certificateId: string; |
| | | 11 | | } |
| | | 12 | | |
| | | 13 | | export interface CustomStackProps extends StackProps { |
| | | 14 | | githubRepo: string; |
| | | 15 | | envName: AppEnvironment; |
| | | 16 | | name: string; |
| | | 17 | | stackName: string; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | export class CustomStack extends Stack { |
| | | 21 | | props: CustomStackProps; |
| | | 22 | | |
| | | 23 | | constructor(scope: Construct, props: CustomStackProps) { |
| | 1 | 24 | | super(scope, getStackName(props), props); |
| | | 25 | | |
| | 1 | 26 | | this.props = props; |
| | | 27 | | |
| | 1 | 28 | | this.addProjectTags(); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | getStackId(): string { |
| | 0 | 32 | | return getStackName(this.props); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | private addProjectTags(): void { |
| | 1 | 36 | | Tags.of(this).add("StackId", getStackName(this.props), { |
| | | 37 | | priority: 300, |
| | | 38 | | }); |
| | | 39 | | |
| | 1 | 40 | | Tags.of(this).add("Environment", this.props.envName.valueOf(), { |
| | | 41 | | priority: 300, |
| | | 42 | | }); |
| | | 43 | | |
| | 1 | 44 | | Tags.of(this).add("Project", this.props.githubRepo, { |
| | | 45 | | priority: 300, |
| | | 46 | | }); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public getCloudFormationRepoName(): string { |
| | 2 | 50 | | return formatRepoNameForCloudFormation(this.props.githubRepo); |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | function getStackName(props: CustomStackProps): string { |
| | 2 | 55 | | return `macalbert-${formatRepoNameForCloudFormation(props.githubRepo)}-${props.name}-${props.envName}-stack`.toLowerCa |
| | | 56 | | } |