@studion/infra-code-blocks 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +293 -36
- package/dist/components/database.d.ts +15 -11
- package/dist/components/database.js +22 -13
- package/dist/components/ec2-ssm-connect.d.ts +6 -2
- package/dist/components/ec2-ssm-connect.js +19 -8
- package/dist/components/ecs-service.d.ts +125 -0
- package/dist/components/ecs-service.js +323 -0
- package/dist/components/mongo.d.ts +27 -0
- package/dist/components/mongo.js +63 -0
- package/dist/components/nuxt-ssr.d.ts +43 -0
- package/dist/components/nuxt-ssr.js +277 -0
- package/dist/components/project.d.ts +32 -15
- package/dist/components/project.js +62 -22
- package/dist/components/static-site.d.ts +3 -3
- package/dist/components/static-site.js +22 -23
- package/dist/components/web-server.d.ts +12 -81
- package/dist/components/web-server.js +46 -244
- package/dist/constants.d.ts +0 -5
- package/dist/constants.js +1 -6
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -4,9 +4,15 @@ Studion Platform common infra components.
|
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
|
-
1. [
|
|
8
|
-
2. [
|
|
9
|
-
3. [
|
|
7
|
+
1. [Prerequisites](#prerequisites)
|
|
8
|
+
2. [Installation](#installation)
|
|
9
|
+
3. [Usage](#usage)
|
|
10
|
+
4. [API](#api)
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- Working [Pulumi](https://www.pulumi.com/docs/clouds/aws/get-started/begin/#pulumi-aws-before-you-begin) project
|
|
15
|
+
- AWS account with neccessary permissions for each studion component
|
|
10
16
|
|
|
11
17
|
## Installation
|
|
12
18
|
|
|
@@ -42,6 +48,12 @@ const project = new studion.Project('demo-project', {
|
|
|
42
48
|
export const projectName = project.name;
|
|
43
49
|
```
|
|
44
50
|
|
|
51
|
+
- Deploy pulumi stack
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
$ pulumi up
|
|
55
|
+
```
|
|
56
|
+
|
|
45
57
|
## API
|
|
46
58
|
|
|
47
59
|
1. [Project](#project)
|
|
@@ -49,6 +61,9 @@ export const projectName = project.name;
|
|
|
49
61
|
3. [Redis](#redis)
|
|
50
62
|
4. [StaticSite](#static-site)
|
|
51
63
|
5. [WebServer](#web-server)
|
|
64
|
+
6. [Nuxt SSR](#nuxt-ssr-preset)
|
|
65
|
+
7. [Mongo](#mongo)
|
|
66
|
+
8. [EcsService](#ecs-service)
|
|
52
67
|
|
|
53
68
|
### Project
|
|
54
69
|
|
|
@@ -70,12 +85,14 @@ new Project(name: string, args: ProjectArgs, opts?: pulumi.CustomResourceOptions
|
|
|
70
85
|
```ts
|
|
71
86
|
type ProjectArgs = {
|
|
72
87
|
services: (
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
88
|
+
| DatabaseServiceOptions
|
|
89
|
+
| RedisServiceOptions
|
|
90
|
+
| StaticSiteServiceOptions
|
|
91
|
+
| WebServerServiceOptions
|
|
92
|
+
| NuxtSSRServiceOptions
|
|
93
|
+
| MongoServiceOptions
|
|
94
|
+
| EcsServiceOptions
|
|
77
95
|
)[];
|
|
78
|
-
hostedZoneId?: pulumi.Input<string>;
|
|
79
96
|
enableSSMConnect?: pulumi.Input<boolean>;
|
|
80
97
|
};
|
|
81
98
|
```
|
|
@@ -83,16 +100,15 @@ type ProjectArgs = {
|
|
|
83
100
|
| Argument | Description |
|
|
84
101
|
| :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
85
102
|
| services \* | Service list. |
|
|
86
|
-
| hostedZoneId | Route53 hosted zone ID responsible for managing records for the domain. |
|
|
87
103
|
| enableSSMConnect | Setup ec2 instance and SSM in order to connect to the database in the private subnet. Please refer to the [SSM Connect](#ssm-connect) section for more info. |
|
|
88
104
|
|
|
89
105
|
```ts
|
|
90
|
-
type
|
|
106
|
+
type DatabaseServiceOptions = {
|
|
91
107
|
type: 'DATABASE';
|
|
92
108
|
serviceName: string;
|
|
93
109
|
dbName: pulumi.Input<string>;
|
|
94
110
|
username: pulumi.Input<string>;
|
|
95
|
-
password
|
|
111
|
+
password?: pulumi.Input<string>;
|
|
96
112
|
applyImmediately?: pulumi.Input<boolean>;
|
|
97
113
|
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
98
114
|
allocatedStorage?: pulumi.Input<number>;
|
|
@@ -105,7 +121,7 @@ type DatabaseService = {
|
|
|
105
121
|
```
|
|
106
122
|
|
|
107
123
|
```ts
|
|
108
|
-
export type
|
|
124
|
+
export type RedisServiceOptions = {
|
|
109
125
|
type: 'REDIS';
|
|
110
126
|
serviceName: string;
|
|
111
127
|
dbName: pulumi.Input<string>;
|
|
@@ -114,10 +130,11 @@ export type RedisService = {
|
|
|
114
130
|
```
|
|
115
131
|
|
|
116
132
|
```ts
|
|
117
|
-
export type
|
|
133
|
+
export type StaticSiteServiceOptions = {
|
|
118
134
|
type: 'STATIC_SITE';
|
|
119
135
|
serviceName: string;
|
|
120
|
-
domain
|
|
136
|
+
domain?: pulumi.Input<string>;
|
|
137
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
121
138
|
tags?: pulumi.Input<{
|
|
122
139
|
[key: string]: pulumi.Input<string>;
|
|
123
140
|
}>;
|
|
@@ -125,21 +142,103 @@ export type StaticSiteService = {
|
|
|
125
142
|
```
|
|
126
143
|
|
|
127
144
|
```ts
|
|
128
|
-
export type
|
|
145
|
+
export type WebServerServiceOptions = {
|
|
129
146
|
type: 'WEB_SERVER';
|
|
130
147
|
serviceName: string;
|
|
148
|
+
image: pulumi.Input<string>;
|
|
149
|
+
port: pulumi.Input<number>;
|
|
150
|
+
domain?: pulumi.Input<string>;
|
|
151
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
152
|
+
environment?:
|
|
153
|
+
| aws.ecs.KeyValuePair[]
|
|
154
|
+
| ((services: Services) => aws.ecs.KeyValuePair[]);
|
|
155
|
+
secrets?: aws.ecs.Secret[] | ((services: Services) => aws.ecs.Secret[]);
|
|
156
|
+
desiredCount?: pulumi.Input<number>;
|
|
157
|
+
autoscaling?: pulumi.Input<{
|
|
158
|
+
enabled: pulumi.Input<boolean>;
|
|
159
|
+
minCount?: pulumi.Input<number>;
|
|
160
|
+
maxCount?: pulumi.Input<number>;
|
|
161
|
+
}>;
|
|
162
|
+
size?: pulumi.Input<Size>;
|
|
163
|
+
healthCheckPath?: pulumi.Input<string>;
|
|
164
|
+
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
165
|
+
pulumi.Input<RoleInlinePolicy>[]
|
|
166
|
+
>;
|
|
167
|
+
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
168
|
+
tags?: pulumi.Input<{
|
|
169
|
+
[key: string]: pulumi.Input<string>;
|
|
170
|
+
}>;
|
|
171
|
+
};
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
export type NuxtSSRServiceOptions = {
|
|
176
|
+
type: 'NUXT_SSR';
|
|
177
|
+
serviceName: string;
|
|
178
|
+
image: pulumi.Input<string>;
|
|
179
|
+
port: pulumi.Input<number>;
|
|
180
|
+
domain?: pulumi.Input<string>;
|
|
181
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
131
182
|
environment?:
|
|
132
183
|
| aws.ecs.KeyValuePair[]
|
|
133
184
|
| ((services: Services) => aws.ecs.KeyValuePair[]);
|
|
134
185
|
secrets?: aws.ecs.Secret[] | ((services: Services) => aws.ecs.Secret[]);
|
|
186
|
+
desiredCount?: pulumi.Input<number>;
|
|
187
|
+
autoscaling?: pulumi.Input<{
|
|
188
|
+
enabled: pulumi.Input<boolean>;
|
|
189
|
+
minCount?: pulumi.Input<number>;
|
|
190
|
+
maxCount?: pulumi.Input<number>;
|
|
191
|
+
}>;
|
|
192
|
+
size?: pulumi.Input<Size>;
|
|
193
|
+
healthCheckPath?: pulumi.Input<string>;
|
|
194
|
+
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
195
|
+
pulumi.Input<RoleInlinePolicy>[]
|
|
196
|
+
>;
|
|
197
|
+
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
198
|
+
tags?: pulumi.Input<{
|
|
199
|
+
[key: string]: pulumi.Input<string>;
|
|
200
|
+
}>;
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
type MongoServiceOptions = {
|
|
206
|
+
type: 'MONGO';
|
|
207
|
+
serviceName: string;
|
|
208
|
+
username: pulumi.Input<string>;
|
|
209
|
+
password?: pulumi.Input<string>;
|
|
210
|
+
port?: pulumi.Input<number>;
|
|
211
|
+
size?: pulumi.Input<Size>;
|
|
212
|
+
tags?: pulumi.Input<{
|
|
213
|
+
[key: string]: pulumi.Input<string>;
|
|
214
|
+
}>;
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
type EcsServiceOptions = {
|
|
220
|
+
type: 'ECS_SERVICE';
|
|
221
|
+
serviceName: string;
|
|
135
222
|
image: pulumi.Input<string>;
|
|
136
223
|
port: pulumi.Input<number>;
|
|
137
|
-
|
|
224
|
+
enableServiceAutoDiscovery: pulumi.Input<boolean>;
|
|
225
|
+
lbTargetGroupArn?: aws.lb.TargetGroup['arn'];
|
|
226
|
+
persistentStorageVolumePath?: pulumi.Input<string>;
|
|
227
|
+
securityGroup?: aws.ec2.SecurityGroup;
|
|
228
|
+
assignPublicIp?: pulumi.Input<boolean>;
|
|
229
|
+
dockerCommand?: pulumi.Input<string[]>;
|
|
230
|
+
environment?:
|
|
231
|
+
| aws.ecs.KeyValuePair[]
|
|
232
|
+
| ((services: Services) => aws.ecs.KeyValuePair[]);
|
|
233
|
+
secrets?: aws.ecs.Secret[] | ((services: Services) => aws.ecs.Secret[]);
|
|
138
234
|
desiredCount?: pulumi.Input<number>;
|
|
139
|
-
|
|
140
|
-
|
|
235
|
+
autoscaling?: pulumi.Input<{
|
|
236
|
+
enabled: pulumi.Input<boolean>;
|
|
237
|
+
minCount?: pulumi.Input<number>;
|
|
238
|
+
maxCount?: pulumi.Input<number>;
|
|
239
|
+
}>;
|
|
141
240
|
size?: pulumi.Input<Size>;
|
|
142
|
-
|
|
241
|
+
healthCheckPath?: pulumi.Input<string>;
|
|
143
242
|
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
144
243
|
pulumi.Input<RoleInlinePolicy>[]
|
|
145
244
|
>;
|
|
@@ -156,7 +255,6 @@ recieves services bag as argument.
|
|
|
156
255
|
|
|
157
256
|
```ts
|
|
158
257
|
const project = new studion.Project('demo-project', {
|
|
159
|
-
environment: 'DEVELOPMENT',
|
|
160
258
|
services: [
|
|
161
259
|
{
|
|
162
260
|
type: 'REDIS',
|
|
@@ -169,6 +267,7 @@ const project = new studion.Project('demo-project', {
|
|
|
169
267
|
image: imageUri,
|
|
170
268
|
port: 3000,
|
|
171
269
|
domain: 'api.my-domain.com',
|
|
270
|
+
hostedZoneId: 'my-domain.com-hostedZoneId',
|
|
172
271
|
environment: (services: Services) => {
|
|
173
272
|
const redisServiceName = 'redis';
|
|
174
273
|
const redis = services[redisServiceName];
|
|
@@ -187,7 +286,6 @@ Secret Manager based on arn that is provided for the `valueFrom` field.
|
|
|
187
286
|
|
|
188
287
|
```ts
|
|
189
288
|
const project = new studion.Project('demo-project', {
|
|
190
|
-
environment: 'DEVELOPMENT',
|
|
191
289
|
services: [
|
|
192
290
|
{
|
|
193
291
|
type: 'WEB_SERVER',
|
|
@@ -195,6 +293,7 @@ const project = new studion.Project('demo-project', {
|
|
|
195
293
|
image: imageUri,
|
|
196
294
|
port: 3000,
|
|
197
295
|
domain: 'api.my-domain.com',
|
|
296
|
+
hostedZoneId: 'my-domain.com-hostedZoneId',
|
|
198
297
|
secrets: [
|
|
199
298
|
{ name: 'DB_PASSWORD', valueFrom: 'arn-of-the-secret-manager-secret' },
|
|
200
299
|
],
|
|
@@ -205,7 +304,6 @@ const project = new studion.Project('demo-project', {
|
|
|
205
304
|
|
|
206
305
|
```ts
|
|
207
306
|
const project = new studion.Project('demo-project', {
|
|
208
|
-
environment: 'DEVELOPMENT',
|
|
209
307
|
services: [
|
|
210
308
|
{
|
|
211
309
|
type: 'REDIS',
|
|
@@ -218,6 +316,7 @@ const project = new studion.Project('demo-project', {
|
|
|
218
316
|
image: imageUri,
|
|
219
317
|
port: 3000,
|
|
220
318
|
domain: 'api.my-domain.com',
|
|
319
|
+
hostedZoneId: 'my-domain.com-hostedZoneId',
|
|
221
320
|
secrets: (services: Services) => {
|
|
222
321
|
const redisServiceName = 'redis';
|
|
223
322
|
const redis = services[redisServiceName];
|
|
@@ -256,8 +355,10 @@ new Database(name: string, args: DatabaseArgs, opts?: pulumi.CustomResourceOptio
|
|
|
256
355
|
type DatabaseArgs = {
|
|
257
356
|
dbName: pulumi.Input<string>;
|
|
258
357
|
username: pulumi.Input<string>;
|
|
259
|
-
|
|
260
|
-
|
|
358
|
+
vpcId: pulumi.Input<string>;
|
|
359
|
+
isolatedSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
360
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
361
|
+
password?: pulumi.Input<string>;
|
|
261
362
|
applyImmediately?: pulumi.Input<boolean>;
|
|
262
363
|
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
263
364
|
allocatedStorage?: pulumi.Input<number>;
|
|
@@ -269,6 +370,7 @@ type DatabaseArgs = {
|
|
|
269
370
|
};
|
|
270
371
|
```
|
|
271
372
|
|
|
373
|
+
If the password is not specified it will be autogenerated.
|
|
272
374
|
The database password is stored as a secret inside AWS Secret Manager.
|
|
273
375
|
The secret will be available on the `Database` resource as `passwordSecret`.
|
|
274
376
|
|
|
@@ -318,7 +420,7 @@ will exist on the resource.
|
|
|
318
420
|
|
|
319
421
|
### Static Site
|
|
320
422
|
|
|
321
|
-
AWS S3 + Cloudfront
|
|
423
|
+
AWS S3 + Cloudfront.
|
|
322
424
|
|
|
323
425
|
Features:
|
|
324
426
|
|
|
@@ -341,8 +443,8 @@ new StaticSite(name: string, args: StaticSiteArgs, opts?: pulumi.ComponentResour
|
|
|
341
443
|
|
|
342
444
|
```ts
|
|
343
445
|
type StaticSiteArgs = {
|
|
344
|
-
domain
|
|
345
|
-
hostedZoneId
|
|
446
|
+
domain?: pulumi.Input<string>;
|
|
447
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
346
448
|
tags?: pulumi.Input<{
|
|
347
449
|
[key: string]: pulumi.Input<string>;
|
|
348
450
|
}>;
|
|
@@ -351,11 +453,11 @@ type StaticSiteArgs = {
|
|
|
351
453
|
|
|
352
454
|
### Web Server
|
|
353
455
|
|
|
354
|
-
AWS ECS Fargate
|
|
456
|
+
AWS ECS Fargate.
|
|
355
457
|
|
|
356
458
|
Features:
|
|
357
459
|
|
|
358
|
-
-
|
|
460
|
+
- memory and CPU autoscaling enabled
|
|
359
461
|
- creates TLS certificate for the specified domain
|
|
360
462
|
- redirects HTTP traffic to HTTPS
|
|
361
463
|
- creates CloudWatch log group
|
|
@@ -377,17 +479,173 @@ new WebServer(name: string, args: WebServerArgs, opts?: pulumi.ComponentResource
|
|
|
377
479
|
export type WebServerArgs = {
|
|
378
480
|
image: pulumi.Input<string>;
|
|
379
481
|
port: pulumi.Input<number>;
|
|
380
|
-
domain: pulumi.Input<string>;
|
|
381
482
|
cluster: aws.ecs.Cluster;
|
|
382
|
-
|
|
383
|
-
|
|
483
|
+
vpcId: pulumi.Input<string>;
|
|
484
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
485
|
+
publicSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
486
|
+
domain?: pulumi.Input<string>;
|
|
487
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
384
488
|
desiredCount?: pulumi.Input<number>;
|
|
385
|
-
|
|
386
|
-
|
|
489
|
+
autoscaling?: pulumi.Input<{
|
|
490
|
+
enabled: pulumi.Input<boolean>;
|
|
491
|
+
minCount?: pulumi.Input<number>;
|
|
492
|
+
maxCount?: pulumi.Input<number>;
|
|
493
|
+
}>;
|
|
494
|
+
size?: pulumi.Input<Size>;
|
|
495
|
+
environment?: aws.ecs.KeyValuePair[];
|
|
496
|
+
secrets?: aws.ecs.Secret[];
|
|
497
|
+
healthCheckPath?: pulumi.Input<string>;
|
|
498
|
+
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
499
|
+
pulumi.Input<RoleInlinePolicy>[]
|
|
500
|
+
>;
|
|
501
|
+
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
502
|
+
tags?: pulumi.Input<{
|
|
503
|
+
[key: string]: pulumi.Input<string>;
|
|
504
|
+
}>;
|
|
505
|
+
};
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Nuxt SSR preset
|
|
509
|
+
|
|
510
|
+
AWS ECS Fargate + Cloudfront.
|
|
511
|
+
|
|
512
|
+
Features:
|
|
513
|
+
|
|
514
|
+
- memory and CPU autoscaling enabled
|
|
515
|
+
- creates TLS certificate for the specified domain
|
|
516
|
+
- redirects HTTP traffic to HTTPS
|
|
517
|
+
- creates CloudWatch log group
|
|
518
|
+
- comes with predefined cpu and memory options: `small`, `medium`, `large`, `xlarge`
|
|
519
|
+
- CDN in front of the application load balancer for static resource caching
|
|
520
|
+
|
|
521
|
+
<br>
|
|
522
|
+
|
|
523
|
+
```ts
|
|
524
|
+
new NuxtSSR(name: string, args: NuxtSSRArgs, opts?: pulumi.ComponentResourceOptions );
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
| Argument | Description |
|
|
528
|
+
| :------- | :--------------------------------------------: |
|
|
529
|
+
| name \* | The unique name of the resource. |
|
|
530
|
+
| args \* | The arguments to resource properties. |
|
|
531
|
+
| opts | Bag of options to control resource's behavior. |
|
|
532
|
+
|
|
533
|
+
```ts
|
|
534
|
+
export type NuxtSSRArgs = {
|
|
535
|
+
image: pulumi.Input<string>;
|
|
536
|
+
port: pulumi.Input<number>;
|
|
537
|
+
cluster: aws.ecs.Cluster;
|
|
538
|
+
vpcId: pulumi.Input<string>;
|
|
539
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
540
|
+
publicSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
541
|
+
domain?: pulumi.Input<string>;
|
|
542
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
543
|
+
desiredCount?: pulumi.Input<number>;
|
|
544
|
+
autoscaling?: pulumi.Input<{
|
|
545
|
+
enabled: pulumi.Input<boolean>;
|
|
546
|
+
minCount?: pulumi.Input<number>;
|
|
547
|
+
maxCount?: pulumi.Input<number>;
|
|
548
|
+
}>;
|
|
549
|
+
size?: pulumi.Input<Size>;
|
|
550
|
+
environment?: aws.ecs.KeyValuePair[];
|
|
551
|
+
secrets?: aws.ecs.Secret[];
|
|
552
|
+
healthCheckPath?: pulumi.Input<string>;
|
|
553
|
+
tags?: pulumi.Input<{
|
|
554
|
+
[key: string]: pulumi.Input<string>;
|
|
555
|
+
}>;
|
|
556
|
+
};
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
### Mongo
|
|
560
|
+
|
|
561
|
+
AWS ECS Fargate.
|
|
562
|
+
|
|
563
|
+
Features:
|
|
564
|
+
|
|
565
|
+
- persistent storage
|
|
566
|
+
- service auto-discovery
|
|
567
|
+
- creates CloudWatch log group
|
|
568
|
+
- comes with predefined cpu and memory options: `small`, `medium`, `large`, `xlarge`
|
|
569
|
+
|
|
570
|
+
<br>
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
new Mongo(name: string, args: MongoArgs, opts?: pulumi.ComponentResourceOptions );
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
| Argument | Description |
|
|
577
|
+
| :------- | :--------------------------------------------: |
|
|
578
|
+
| name \* | The unique name of the resource. |
|
|
579
|
+
| args \* | The arguments to resource properties. |
|
|
580
|
+
| opts | Bag of options to control resource's behavior. |
|
|
581
|
+
|
|
582
|
+
```ts
|
|
583
|
+
export type MongoArgs = {
|
|
584
|
+
cluster: aws.ecs.Cluster;
|
|
585
|
+
vpcId: pulumi.Input<string>;
|
|
586
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
587
|
+
privateSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
588
|
+
username: pulumi.Input<string>;
|
|
589
|
+
password?: pulumi.Input<string>;
|
|
590
|
+
port?: pulumi.Input<number>;
|
|
591
|
+
size?: pulumi.Input<Size>;
|
|
592
|
+
tags?: pulumi.Input<{
|
|
593
|
+
[key: string]: pulumi.Input<string>;
|
|
594
|
+
}>;
|
|
595
|
+
};
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
If the password is not specified it will be autogenerated.
|
|
599
|
+
The mongo password is stored as a secret inside AWS Secret Manager.
|
|
600
|
+
The secret will be available on the `Mongo` resource as `passwordSecret`.
|
|
601
|
+
|
|
602
|
+
### Ecs Service
|
|
603
|
+
|
|
604
|
+
AWS ECS Fargate.
|
|
605
|
+
|
|
606
|
+
Features:
|
|
607
|
+
|
|
608
|
+
- memory and CPU autoscaling
|
|
609
|
+
- service auto discovery
|
|
610
|
+
- persistent storage
|
|
611
|
+
- CloudWatch logs
|
|
612
|
+
- comes with predefined cpu and memory options: `small`, `medium`, `large`, `xlarge`
|
|
613
|
+
|
|
614
|
+
<br>
|
|
615
|
+
|
|
616
|
+
```ts
|
|
617
|
+
new EcsService(name: string, args: EcsServiceArgs, opts?: pulumi.ComponentResourceOptions );
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
| Argument | Description |
|
|
621
|
+
| :------- | :--------------------------------------------: |
|
|
622
|
+
| name \* | The unique name of the resource. |
|
|
623
|
+
| args \* | The arguments to resource properties. |
|
|
624
|
+
| opts | Bag of options to control resource's behavior. |
|
|
625
|
+
|
|
626
|
+
```ts
|
|
627
|
+
export type EcsServiceArgs = {
|
|
628
|
+
image: pulumi.Input<string>;
|
|
629
|
+
port: pulumi.Input<number>;
|
|
630
|
+
cluster: aws.ecs.Cluster;
|
|
631
|
+
vpcId: pulumi.Input<string>;
|
|
632
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
633
|
+
subnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
634
|
+
desiredCount?: pulumi.Input<number>;
|
|
635
|
+
autoscaling?: pulumi.Input<{
|
|
636
|
+
enabled: pulumi.Input<boolean>;
|
|
637
|
+
minCount?: pulumi.Input<number>;
|
|
638
|
+
maxCount?: pulumi.Input<number>;
|
|
639
|
+
}>;
|
|
387
640
|
size?: pulumi.Input<Size>;
|
|
388
641
|
environment?: aws.ecs.KeyValuePair[];
|
|
389
642
|
secrets?: aws.ecs.Secret[];
|
|
390
|
-
|
|
643
|
+
enableServiceAutoDiscovery: pulumi.Input<boolean>;
|
|
644
|
+
persistentStorageVolumePath?: pulumi.Input<string>;
|
|
645
|
+
dockerCommand?: pulumi.Input<string[]>;
|
|
646
|
+
lbTargetGroupArn?: aws.lb.TargetGroup['arn'];
|
|
647
|
+
securityGroup?: aws.ec2.SecurityGroup;
|
|
648
|
+
assignPublicIp?: pulumi.Input<boolean>;
|
|
391
649
|
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
392
650
|
pulumi.Input<RoleInlinePolicy>[]
|
|
393
651
|
>;
|
|
@@ -499,5 +757,4 @@ const project = new studion.Project('demo-project', {
|
|
|
499
757
|
## 🚧 TODO
|
|
500
758
|
|
|
501
759
|
- [ ] Add worker service for executing tasks
|
|
502
|
-
- [ ] Add MongoDB service
|
|
503
760
|
- [ ] Enable RDS password rotation
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as aws from '@pulumi/aws';
|
|
2
|
-
import * as awsx from '@pulumi/awsx';
|
|
3
2
|
import * as pulumi from '@pulumi/pulumi';
|
|
4
3
|
export type DatabaseArgs = {
|
|
5
4
|
/**
|
|
@@ -10,33 +9,38 @@ export type DatabaseArgs = {
|
|
|
10
9
|
* Username for the master DB user.
|
|
11
10
|
*/
|
|
12
11
|
username: pulumi.Input<string>;
|
|
12
|
+
vpcId: pulumi.Input<string>;
|
|
13
|
+
isolatedSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
* The value will be stored as a secret in AWS Secret Manager.
|
|
15
|
+
* The IPv4 CIDR block for the VPC.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Password for the master DB user. If not specified it will be autogenerated.
|
|
20
|
+
* The value will be stored as a secret in AWS Secret Manager.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
password?: pulumi.Input<string>;
|
|
22
23
|
/**
|
|
23
|
-
* Specifies whether any database modifications are applied immediately,
|
|
24
|
+
* Specifies whether any database modifications are applied immediately,
|
|
25
|
+
* or during the next maintenance window. Default is false.
|
|
24
26
|
*/
|
|
25
27
|
applyImmediately?: pulumi.Input<boolean>;
|
|
26
28
|
/**
|
|
27
|
-
* Determines whether a final DB snapshot is created before the DB
|
|
29
|
+
* Determines whether a final DB snapshot is created before the DB
|
|
30
|
+
* instance is deleted. Defaults to false.
|
|
28
31
|
*/
|
|
29
32
|
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
30
33
|
/**
|
|
31
|
-
* The allocated storage in gibibytes.
|
|
34
|
+
* The allocated storage in gibibytes. Defaults to 20GB.
|
|
32
35
|
*/
|
|
33
36
|
allocatedStorage?: pulumi.Input<number>;
|
|
34
37
|
/**
|
|
35
|
-
* The upper limit to which Amazon RDS can automatically scale
|
|
38
|
+
* The upper limit to which Amazon RDS can automatically scale
|
|
39
|
+
* the storage of the DB instance. Defaults to 100GB.
|
|
36
40
|
*/
|
|
37
41
|
maxAllocatedStorage?: pulumi.Input<number>;
|
|
38
42
|
/**
|
|
39
|
-
* The instance type of the RDS instance.
|
|
43
|
+
* The instance type of the RDS instance. Defaults to 'db.t4g.micro'.
|
|
40
44
|
*/
|
|
41
45
|
instanceClass?: pulumi.Input<string>;
|
|
42
46
|
/**
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Database = void 0;
|
|
4
4
|
const aws = require("@pulumi/aws");
|
|
5
5
|
const pulumi = require("@pulumi/pulumi");
|
|
6
|
+
const random = require("@pulumi/random");
|
|
6
7
|
const constants_1 = require("../constants");
|
|
7
8
|
const defaults = {
|
|
8
9
|
applyImmediately: false,
|
|
@@ -15,30 +16,31 @@ class Database extends pulumi.ComponentResource {
|
|
|
15
16
|
constructor(name, args, opts = {}) {
|
|
16
17
|
super('studion:Database', name, {}, opts);
|
|
17
18
|
this.name = name;
|
|
18
|
-
const {
|
|
19
|
-
this.dbSubnetGroup = this.createSubnetGroup({
|
|
20
|
-
this.dbSecurityGroup = this.createSecurityGroup({
|
|
19
|
+
const { vpcId, isolatedSubnetIds, vpcCidrBlock } = args;
|
|
20
|
+
this.dbSubnetGroup = this.createSubnetGroup({ isolatedSubnetIds });
|
|
21
|
+
this.dbSecurityGroup = this.createSecurityGroup({ vpcId, vpcCidrBlock });
|
|
21
22
|
this.kms = this.createEncryptionKey();
|
|
22
|
-
|
|
23
|
-
this.instance =
|
|
23
|
+
const { instance, passwordSecret } = this.createDatabaseInstance(args);
|
|
24
|
+
this.instance = instance;
|
|
25
|
+
this.passwordSecret = passwordSecret;
|
|
24
26
|
this.registerOutputs();
|
|
25
27
|
}
|
|
26
|
-
createSubnetGroup({
|
|
28
|
+
createSubnetGroup({ isolatedSubnetIds, }) {
|
|
27
29
|
const dbSubnetGroup = new aws.rds.SubnetGroup(`${this.name}-subnet-group`, {
|
|
28
|
-
subnetIds:
|
|
30
|
+
subnetIds: isolatedSubnetIds,
|
|
29
31
|
tags: constants_1.commonTags,
|
|
30
32
|
}, { parent: this });
|
|
31
33
|
return dbSubnetGroup;
|
|
32
34
|
}
|
|
33
|
-
createSecurityGroup({
|
|
35
|
+
createSecurityGroup({ vpcId, vpcCidrBlock, }) {
|
|
34
36
|
const dbSecurityGroup = new aws.ec2.SecurityGroup(`${this.name}-security-group`, {
|
|
35
|
-
vpcId
|
|
37
|
+
vpcId,
|
|
36
38
|
ingress: [
|
|
37
39
|
{
|
|
38
40
|
protocol: 'tcp',
|
|
39
41
|
fromPort: 5432,
|
|
40
42
|
toPort: 5432,
|
|
41
|
-
cidrBlocks: [
|
|
43
|
+
cidrBlocks: [vpcCidrBlock],
|
|
42
44
|
},
|
|
43
45
|
],
|
|
44
46
|
tags: constants_1.commonTags,
|
|
@@ -73,16 +75,23 @@ class Database extends pulumi.ComponentResource {
|
|
|
73
75
|
createDatabaseInstance(args) {
|
|
74
76
|
const argsWithDefaults = Object.assign({}, defaults, args);
|
|
75
77
|
const stack = pulumi.getStack();
|
|
78
|
+
const password = argsWithDefaults.password ||
|
|
79
|
+
new random.RandomPassword(`${this.name}-db-password`, {
|
|
80
|
+
length: 16,
|
|
81
|
+
overrideSpecial: '_%$',
|
|
82
|
+
special: true,
|
|
83
|
+
}).result;
|
|
84
|
+
const passwordSecret = this.createPasswordSecret({ password });
|
|
76
85
|
const instance = new aws.rds.Instance(`${this.name}-rds`, {
|
|
77
86
|
identifierPrefix: `${this.name}-`,
|
|
78
87
|
engine: 'postgres',
|
|
79
|
-
engineVersion: '
|
|
88
|
+
engineVersion: '15.3',
|
|
80
89
|
allocatedStorage: argsWithDefaults.allocatedStorage,
|
|
81
90
|
maxAllocatedStorage: argsWithDefaults.maxAllocatedStorage,
|
|
82
91
|
instanceClass: argsWithDefaults.instanceClass,
|
|
83
92
|
dbName: argsWithDefaults.dbName,
|
|
84
93
|
username: argsWithDefaults.username,
|
|
85
|
-
password
|
|
94
|
+
password,
|
|
86
95
|
dbSubnetGroupName: this.dbSubnetGroup.name,
|
|
87
96
|
vpcSecurityGroupIds: [this.dbSecurityGroup.id],
|
|
88
97
|
storageEncrypted: true,
|
|
@@ -97,7 +106,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
97
106
|
backupRetentionPeriod: 14,
|
|
98
107
|
tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags),
|
|
99
108
|
}, { parent: this });
|
|
100
|
-
return instance;
|
|
109
|
+
return { instance, passwordSecret };
|
|
101
110
|
}
|
|
102
111
|
}
|
|
103
112
|
exports.Database = Database;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import * as pulumi from '@pulumi/pulumi';
|
|
2
2
|
import * as aws from '@pulumi/aws';
|
|
3
|
-
import * as awsx from '@pulumi/awsx';
|
|
4
3
|
export type Ec2SSMConnectArgs = {
|
|
5
|
-
|
|
4
|
+
vpcId: pulumi.Input<string>;
|
|
5
|
+
privateSubnetId: pulumi.Input<string>;
|
|
6
|
+
/**
|
|
7
|
+
* The IPv4 CIDR block for the VPC.
|
|
8
|
+
*/
|
|
9
|
+
vpcCidrBlock: pulumi.Input<string>;
|
|
6
10
|
tags?: pulumi.Input<{
|
|
7
11
|
[key: string]: pulumi.Input<string>;
|
|
8
12
|
}>;
|