-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateApp.ts
More file actions
112 lines (105 loc) · 3.98 KB
/
createApp.ts
File metadata and controls
112 lines (105 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import {
App,
Aspects,
Tags,
StackProps
} from "aws-cdk-lib"
import {AwsSolutionsChecks} from "cdk-nag"
import {getConfigFromEnvVar, getBooleanConfigFromEnvVar} from "../config"
import {EpsNagPack} from "../nag/pack/epsNagPack"
export interface StandardStackProps extends StackProps {
/** Semantic version of the deployment (from `versionNumber`). */
readonly version: string
/** Git commit identifier baked into the stack. */
readonly commitId: string
/** Whether the stack originates from a pull-request environment. */
readonly isPullRequest: boolean
/** Logical environment identifier (for example `dev`, `prod`). */
readonly environment: string
/** CDK environment configuration used when synthesizing the stack. */
readonly env: {
/** AWS region targeted by the stack. */
readonly region: string
}
}
export interface CreateAppParams {
readonly productName: string
readonly appName: string
readonly repoName: string
readonly driftDetectionGroup: string
readonly region?: string
readonly projectType?: string
readonly publicFacing?: string
readonly serviceCategory?: string
}
/**
* Initialize a CDK `App` pre-loaded with NHS EPS tags and mandatory configuration.
*
* Reads stack metadata from environment variables, and returns
* both the created `App` instance and the resolved stack props (including version info).
*
* @param params - High-level app metadata and optional deployment modifiers.
* @param params.productName - Product tag value for the stack.
* @param params.appName - Identifier used for `cdkApp` tagging.
* @param params.repoName - Repository name stored on the stack tags.
* @param params.driftDetectionGroup - Baseline drift detection tag (suffixes `-pull-request` when `isPullRequest`).
* @param params.region - AWS region assigned to the stack environment (default `eu-west-2`).
* @param params.projectType - Tag describing the project classification (default `Production`).
* @param params.publicFacing - Public-facing classification tag (default `Y`).
* @param params.serviceCategory - Service category tag (default `Platinum`).
* @returns The constructed CDK `App` and the resolved stack props for downstream stacks.
*/
export function createApp({
productName,
appName,
repoName,
driftDetectionGroup,
region = "eu-west-2",
projectType = "Production",
publicFacing = "Y",
serviceCategory = "Platinum"
}: CreateAppParams): { app: App, props: StandardStackProps } {
const versionNumber = getConfigFromEnvVar("versionNumber")
const commitId = getConfigFromEnvVar("commitId")
const isPullRequest = getBooleanConfigFromEnvVar("isPullRequest")
const environment = getConfigFromEnvVar("environment")
let cfnDriftDetectionGroup = driftDetectionGroup
if (isPullRequest) {
cfnDriftDetectionGroup += "-pull-request"
}
const app = new App()
app.node.setContext("isPullRequest", isPullRequest)
Aspects.of(app).add(new AwsSolutionsChecks({verbose: true}))
Aspects.of(app).add(new EpsNagPack({verbose: true}))
Tags.of(app).add("TagVersion", "1")
Tags.of(app).add("Programme", "EPS")
Tags.of(app).add("Product", productName)
Tags.of(app).add("Owner", "england.epssupport@nhs.net")
Tags.of(app).add("CostCentre", "128997")
Tags.of(app).add("Customer", "NHS England")
Tags.of(app).add("data_classification", "5")
Tags.of(app).add("DataType", "PII")
Tags.of(app).add("Environment", environment)
Tags.of(app).add("ProjectType", projectType)
Tags.of(app).add("PublicFacing", publicFacing)
Tags.of(app).add("ServiceCategory", serviceCategory)
Tags.of(app).add("OnOffPattern", "AlwaysOn")
Tags.of(app).add("DeploymentTool", "CDK")
Tags.of(app).add("version", versionNumber)
Tags.of(app).add("commit", commitId)
Tags.of(app).add("cdkApp", appName)
Tags.of(app).add("repo", repoName)
Tags.of(app).add("cfnDriftDetectionGroup", cfnDriftDetectionGroup)
return {
app,
props: {
env: {
region
},
version: versionNumber,
commitId,
isPullRequest,
environment
}
}
}