-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-stack.ts
117 lines (95 loc) · 2.75 KB
/
app-stack.ts
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
113
114
115
116
117
import { Construct } from 'constructs';
import { App, TerraformStack } from 'cdktf';
import { AwsProvider } from './.gen/providers/aws';
import { ArchiveProvider } from './.gen/providers/archive';
import AppLoadBalancer from './resources/load-balancer';
import AppEFS from './resources/efs';
import AppECSCluster from './resources/ecs-cluster';
import AppECSCodeDeploy from './resources/ecs-codedeploy';
import AppDockerRegistry from './resources/docker-registry';
import AppECSCodePipeline from './resources/ecs-codepipeline';
import AppDB from './resources/db';
import AppVPC from './resources/vpc';
import AppBackup from './resources/backup';
import AppNotifications from './resources/notifications';
import S3ToEFS from './resources/s3-to-efs';
import config from './config';
class AppStack extends TerraformStack {
vpc: AppVPC;
dockerRegistry: AppDockerRegistry;
loadBalancer: AppLoadBalancer;
efsData: AppEFS;
ecsCluster: AppECSCluster;
ecsCodeDeploy: AppECSCodeDeploy;
ecsCodePipeline: AppECSCodePipeline;
db?: AppDB;
backup?: AppBackup;
notifications: AppNotifications;
s3ToEFS: S3ToEFS;
constructor(scope: Construct) {
super(scope, config.appName);
// Providers setup
const { region } = config;
new AwsProvider(this, 'aws', {
region,
defaultTags: {
tags: {
app: config.appName,
},
},
});
new ArchiveProvider(this, 'archive', {});
// VPC
this.vpc = new AppVPC(this);
// Database
if (config.db.createDatabase === true) {
this.db = new AppDB(this);
}
// ECR Repository
this.dockerRegistry = new AppDockerRegistry(this);
// Application Load Banancer
this.loadBalancer = new AppLoadBalancer(this);
// EFS File system
this.efsData = new AppEFS(this, 'data');
this.s3ToEFS = new S3ToEFS(this);
// ECS Cluster
this.ecsCluster = new AppECSCluster(this);
// Allow s3ToEFS lambda and ECS to access the EFS volume
this.efsData.securityGroup.ingress = [
{
protocol: 'tcp',
fromPort: 2049,
toPort: 2049,
securityGroups: [
this.s3ToEFS.securityGroup.id,
this.ecsCluster.securityGroup.id,
],
},
];
// Code Deploy
this.ecsCodeDeploy = new AppECSCodeDeploy(this);
// Code Pipeline
this.ecsCodePipeline = new AppECSCodePipeline(this);
// Allow DB access from ECS
if (config.db.createDatabase === true) {
this.db!.securityGroup.ingress = [
{
protocol: 'tcp',
fromPort: 3306,
toPort: 3306,
securityGroups: [this.ecsCluster.securityGroup.id],
},
];
}
if (config.backup.enabled === true) {
this.backup = new AppBackup(this);
}
this.notifications = new AppNotifications(this);
}
}
export const createAppStack = () => {
const app = new App();
const stack = new AppStack(app);
return { app, stack };
};
export default AppStack;