-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateApp.ts
More file actions
60 lines (53 loc) · 1.55 KB
/
createApp.ts
File metadata and controls
60 lines (53 loc) · 1.55 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
import {
App,
Aspects,
Tags,
StackProps
} from "aws-cdk-lib"
import {AwsSolutionsChecks} from "cdk-nag"
import {getConfigFromEnvVar, getBooleanConfigFromEnvVar, calculateVersionedStackName} from "../config"
export interface StandardStackProps extends StackProps {
readonly stackName: string
readonly version: string
readonly commitId: string
readonly isPullRequest: boolean
}
export function createApp(
appName: string,
repoName: string,
driftDetectionGroup: string,
isStateless: boolean = true,
region: string = "eu-west-2"
): {app: App, props: StandardStackProps} {
let stackName = getConfigFromEnvVar("stackName")
const versionNumber = getConfigFromEnvVar("versionNumber")
const commitId = getConfigFromEnvVar("commitId")
const isPullRequest = getBooleanConfigFromEnvVar("isPullRequest")
let cfnDriftDetectionGroup = driftDetectionGroup
if (isPullRequest) {
cfnDriftDetectionGroup += "-pull-request"
}
const app = new App()
Aspects.of(app).add(new AwsSolutionsChecks({verbose: true}))
Tags.of(app).add("version", versionNumber)
Tags.of(app).add("commit", commitId)
Tags.of(app).add("stackName", stackName)
Tags.of(app).add("cdkApp", appName)
Tags.of(app).add("repo", repoName)
Tags.of(app).add("cfnDriftDetectionGroup", cfnDriftDetectionGroup)
if (isStateless && !isPullRequest) {
stackName = calculateVersionedStackName(stackName, versionNumber)
}
return {
app,
props: {
env: {
region
},
stackName,
version: versionNumber,
commitId,
isPullRequest
}
}
}