@studion/infra-code-blocks 0.0.5 → 0.0.7
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 +67 -9
- package/dist/components/database.d.ts +6 -0
- package/dist/components/database.js +2 -0
- package/dist/components/ec2-ssm-connect.d.ts +3 -0
- package/dist/components/ec2-ssm-connect.js +1 -3
- package/dist/components/project.d.ts +0 -4
- package/dist/components/project.js +4 -3
- package/dist/components/static-site.d.ts +6 -0
- package/dist/components/static-site.js +2 -0
- package/dist/components/web-server.d.ts +6 -0
- package/dist/components/web-server.js +3 -1
- package/dist/constants.d.ts +0 -4
- package/dist/constants.js +1 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,6 @@ import * as studion from '@studion/infra-code-blocks';
|
|
|
30
30
|
import * as studion from '@studion/infra-code-blocks';
|
|
31
31
|
|
|
32
32
|
const project = new studion.Project('demo-project', {
|
|
33
|
-
environment: 'DEVELOPMENT',
|
|
34
33
|
services: [
|
|
35
34
|
{
|
|
36
35
|
type: 'REDIS',
|
|
@@ -76,7 +75,6 @@ type ProjectArgs = {
|
|
|
76
75
|
| StaticSiteService
|
|
77
76
|
| WebServerService
|
|
78
77
|
)[];
|
|
79
|
-
environment: Environment;
|
|
80
78
|
hostedZoneId?: pulumi.Input<string>;
|
|
81
79
|
enableSSMConnect?: pulumi.Input<boolean>;
|
|
82
80
|
};
|
|
@@ -85,7 +83,6 @@ type ProjectArgs = {
|
|
|
85
83
|
| Argument | Description |
|
|
86
84
|
| :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
87
85
|
| services \* | Service list. |
|
|
88
|
-
| environment \* | Environment name. |
|
|
89
86
|
| hostedZoneId | Route53 hosted zone ID responsible for managing records for the domain. |
|
|
90
87
|
| 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. |
|
|
91
88
|
|
|
@@ -101,6 +98,9 @@ type DatabaseService = {
|
|
|
101
98
|
allocatedStorage?: pulumi.Input<number>;
|
|
102
99
|
maxAllocatedStorage?: pulumi.Input<number>;
|
|
103
100
|
instanceClass?: pulumi.Input<string>;
|
|
101
|
+
tags?: pulumi.Input<{
|
|
102
|
+
[key: string]: pulumi.Input<string>;
|
|
103
|
+
}>;
|
|
104
104
|
};
|
|
105
105
|
```
|
|
106
106
|
|
|
@@ -118,6 +118,9 @@ export type StaticSiteService = {
|
|
|
118
118
|
type: 'STATIC_SITE';
|
|
119
119
|
serviceName: string;
|
|
120
120
|
domain: pulumi.Input<string>;
|
|
121
|
+
tags?: pulumi.Input<{
|
|
122
|
+
[key: string]: pulumi.Input<string>;
|
|
123
|
+
}>;
|
|
121
124
|
};
|
|
122
125
|
```
|
|
123
126
|
|
|
@@ -140,6 +143,9 @@ export type WebServerService = {
|
|
|
140
143
|
pulumi.Input<RoleInlinePolicy>[]
|
|
141
144
|
>;
|
|
142
145
|
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
146
|
+
tags?: pulumi.Input<{
|
|
147
|
+
[key: string]: pulumi.Input<string>;
|
|
148
|
+
}>;
|
|
143
149
|
};
|
|
144
150
|
```
|
|
145
151
|
|
|
@@ -177,7 +183,15 @@ const project = new studion.Project('demo-project', {
|
|
|
177
183
|
|
|
178
184
|
### Database
|
|
179
185
|
|
|
180
|
-
RDS Postgres instance.
|
|
186
|
+
AWS RDS Postgres instance.
|
|
187
|
+
|
|
188
|
+
Features:
|
|
189
|
+
|
|
190
|
+
- enabled encryption with a symmetric encryption key
|
|
191
|
+
- deployed inside a private subnet
|
|
192
|
+
- backup enabled with retention period set to 14 days
|
|
193
|
+
|
|
194
|
+
<br>
|
|
181
195
|
|
|
182
196
|
```ts
|
|
183
197
|
new Database(name: string, args: DatabaseArgs, opts?: pulumi.CustomResourceOptions);
|
|
@@ -200,12 +214,31 @@ type DatabaseArgs = {
|
|
|
200
214
|
allocatedStorage?: pulumi.Input<number>;
|
|
201
215
|
maxAllocatedStorage?: pulumi.Input<number>;
|
|
202
216
|
instanceClass?: pulumi.Input<string>;
|
|
217
|
+
tags?: pulumi.Input<{
|
|
218
|
+
[key: string]: pulumi.Input<string>;
|
|
219
|
+
}>;
|
|
203
220
|
};
|
|
204
221
|
```
|
|
205
222
|
|
|
206
223
|
### Redis
|
|
207
224
|
|
|
208
|
-
Upstash Redis instance.
|
|
225
|
+
[Upstash](https://upstash.com) Redis instance.
|
|
226
|
+
|
|
227
|
+
**Prerequisites**
|
|
228
|
+
|
|
229
|
+
1. Stack Config
|
|
230
|
+
|
|
231
|
+
| Name | Description | Secret |
|
|
232
|
+
| :---------------- | :-----------------: | :----: |
|
|
233
|
+
| upstash:email \* | Upstash user email. | true |
|
|
234
|
+
| upstash:apiKey \* | Upstash API key. | true |
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
$ pulumi config set --secret upstash:email myemail@example.com
|
|
238
|
+
$ pulumi config set --secret upstash:apiKey my-api-key
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
<br>
|
|
209
242
|
|
|
210
243
|
```ts
|
|
211
244
|
new Redis(name: string, args: RedisArgs, opts: RedisOptions);
|
|
@@ -230,7 +263,16 @@ interface RedisOptions extends pulumi.ComponentResourceOptions {
|
|
|
230
263
|
|
|
231
264
|
### Static Site
|
|
232
265
|
|
|
233
|
-
|
|
266
|
+
AWS S3 + Cloudfront static site.
|
|
267
|
+
|
|
268
|
+
Features:
|
|
269
|
+
|
|
270
|
+
- creates TLS certificate for the specified domain
|
|
271
|
+
- redirects HTTP traffic to HTTPS
|
|
272
|
+
- enables http2 and http3 protocols
|
|
273
|
+
- uses North America and Europe edge locations
|
|
274
|
+
|
|
275
|
+
<br>
|
|
234
276
|
|
|
235
277
|
```ts
|
|
236
278
|
new StaticSite(name: string, args: StaticSiteArgs, opts?: pulumi.ComponentResourceOptions );
|
|
@@ -246,12 +288,25 @@ new StaticSite(name: string, args: StaticSiteArgs, opts?: pulumi.ComponentResour
|
|
|
246
288
|
type StaticSiteArgs = {
|
|
247
289
|
domain: pulumi.Input<string>;
|
|
248
290
|
hostedZoneId: pulumi.Input<string>;
|
|
291
|
+
tags?: pulumi.Input<{
|
|
292
|
+
[key: string]: pulumi.Input<string>;
|
|
293
|
+
}>;
|
|
249
294
|
};
|
|
250
295
|
```
|
|
251
296
|
|
|
252
297
|
### Web Server
|
|
253
298
|
|
|
254
|
-
|
|
299
|
+
AWS ECS Fargate web server.
|
|
300
|
+
|
|
301
|
+
Features:
|
|
302
|
+
|
|
303
|
+
- Memory and CPU autoscaling enabled
|
|
304
|
+
- creates TLS certificate for the specified domain
|
|
305
|
+
- redirects HTTP traffic to HTTPS
|
|
306
|
+
- creates CloudWatch log group
|
|
307
|
+
- comes with predefined cpu and memory options: `small`, `medium`, `large`, `xlarge`
|
|
308
|
+
|
|
309
|
+
<br>
|
|
255
310
|
|
|
256
311
|
```ts
|
|
257
312
|
new WebServer(name: string, args: WebServerArgs, opts?: pulumi.ComponentResourceOptions );
|
|
@@ -281,6 +336,9 @@ export type WebServerArgs = {
|
|
|
281
336
|
pulumi.Input<RoleInlinePolicy>[]
|
|
282
337
|
>;
|
|
283
338
|
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
339
|
+
tags?: pulumi.Input<{
|
|
340
|
+
[key: string]: pulumi.Input<string>;
|
|
341
|
+
}>;
|
|
284
342
|
};
|
|
285
343
|
```
|
|
286
344
|
|
|
@@ -310,7 +368,7 @@ aws ecs execute-command \
|
|
|
310
368
|
--interactive
|
|
311
369
|
```
|
|
312
370
|
|
|
313
|
-
Where
|
|
371
|
+
Where `CLUSTER_NAME` is the name of the ECS cluster and `TASK_FAMILY_NAME` is the name of the task family that task belongs to.
|
|
314
372
|
|
|
315
373
|
## SSM Connect
|
|
316
374
|
|
|
@@ -403,4 +461,4 @@ const project = new studion.Project('demo-project', {
|
|
|
403
461
|
## 🚧 TODO
|
|
404
462
|
|
|
405
463
|
- [ ] Add worker service for executing tasks
|
|
406
|
-
- [ ]
|
|
464
|
+
- [ ] Add MongoDB service
|
|
@@ -38,6 +38,12 @@ export type DatabaseArgs = {
|
|
|
38
38
|
* The instance type of the RDS instance.
|
|
39
39
|
*/
|
|
40
40
|
instanceClass?: pulumi.Input<string>;
|
|
41
|
+
/**
|
|
42
|
+
* A map of tags to assign to the resource.
|
|
43
|
+
*/
|
|
44
|
+
tags?: pulumi.Input<{
|
|
45
|
+
[key: string]: pulumi.Input<string>;
|
|
46
|
+
}>;
|
|
41
47
|
};
|
|
42
48
|
export declare class Database extends pulumi.ComponentResource {
|
|
43
49
|
instance: aws.rds.Instance;
|
|
@@ -29,6 +29,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
29
29
|
],
|
|
30
30
|
}, { parent: this });
|
|
31
31
|
this.kms = new aws.kms.Key(`${name}-rds-key`, {
|
|
32
|
+
description: `${name} RDS encryption key`,
|
|
32
33
|
customerMasterKeySpec: 'SYMMETRIC_DEFAULT',
|
|
33
34
|
isEnabled: true,
|
|
34
35
|
keyUsage: 'ENCRYPT_DECRYPT',
|
|
@@ -57,6 +58,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
57
58
|
finalSnapshotIdentifier: `${name}-final-snapshot`,
|
|
58
59
|
backupWindow: '06:00-06:30',
|
|
59
60
|
backupRetentionPeriod: 14,
|
|
61
|
+
tags: argsWithDefaults.tags,
|
|
60
62
|
}, { parent: this });
|
|
61
63
|
this.registerOutputs();
|
|
62
64
|
}
|
|
@@ -4,6 +4,9 @@ import * as awsx from '@pulumi/awsx';
|
|
|
4
4
|
export type Ec2SSMConnectArgs = {
|
|
5
5
|
vpc: awsx.ec2.Vpc;
|
|
6
6
|
sshPublicKey: pulumi.Input<string>;
|
|
7
|
+
tags?: pulumi.Input<{
|
|
8
|
+
[key: string]: pulumi.Input<string>;
|
|
9
|
+
}>;
|
|
7
10
|
};
|
|
8
11
|
export declare class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
9
12
|
ec2SecurityGroup: aws.ec2.SecurityGroup;
|
|
@@ -67,9 +67,7 @@ class Ec2SSMConnect extends pulumi.ComponentResource {
|
|
|
67
67
|
iamInstanceProfile: ssmProfile.name,
|
|
68
68
|
subnetId,
|
|
69
69
|
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
|
|
70
|
-
tags: {
|
|
71
|
-
Name: `${name}-ec2`,
|
|
72
|
-
},
|
|
70
|
+
tags: Object.assign({ Name: `${name}-ec2` }, args.tags),
|
|
73
71
|
}, { parent: this });
|
|
74
72
|
this.ssmVpcEndpoint = new aws.ec2.VpcEndpoint(`${name}-ssm-vpc-endpoint`, {
|
|
75
73
|
vpcId: args.vpc.vpcId,
|
|
@@ -6,7 +6,6 @@ import { Database, DatabaseArgs } from './database';
|
|
|
6
6
|
import { WebServer, WebServerArgs } from './web-server';
|
|
7
7
|
import { Redis, RedisArgs } from './redis';
|
|
8
8
|
import { StaticSite, StaticSiteArgs } from './static-site';
|
|
9
|
-
import { Environment } from '../constants';
|
|
10
9
|
import { Ec2SSMConnect } from './ec2-ssm-connect';
|
|
11
10
|
export type Service = Database | Redis | StaticSite | WebServer;
|
|
12
11
|
export type Services = Record<string, Service>;
|
|
@@ -29,10 +28,8 @@ export type WebServerService = {
|
|
|
29
28
|
type: 'WEB_SERVER';
|
|
30
29
|
environment?: aws.ecs.KeyValuePair[] | ((services: Services) => aws.ecs.KeyValuePair[]);
|
|
31
30
|
} & ServiceArgs & Omit<WebServerArgs, 'cluster' | 'vpc' | 'hostedZoneId' | 'environment'>;
|
|
32
|
-
export type Environment = (typeof Environment)[keyof typeof Environment];
|
|
33
31
|
export type ProjectArgs = {
|
|
34
32
|
services: (DatabaseService | RedisService | StaticSiteService | WebServerService)[];
|
|
35
|
-
environment: Environment;
|
|
36
33
|
hostedZoneId?: pulumi.Input<string>;
|
|
37
34
|
enableSSMConnect?: pulumi.Input<boolean>;
|
|
38
35
|
};
|
|
@@ -41,7 +38,6 @@ export declare class MissingHostedZoneId extends Error {
|
|
|
41
38
|
}
|
|
42
39
|
export declare class Project extends pulumi.ComponentResource {
|
|
43
40
|
name: string;
|
|
44
|
-
environment: Environment;
|
|
45
41
|
vpc: awsx.ec2.Vpc;
|
|
46
42
|
cluster?: aws.ecs.Cluster;
|
|
47
43
|
hostedZoneId?: pulumi.Input<string>;
|
|
@@ -33,10 +33,9 @@ class Project extends pulumi.ComponentResource {
|
|
|
33
33
|
constructor(name, args, opts = {}) {
|
|
34
34
|
super('studion:Project', name, {}, opts);
|
|
35
35
|
this.services = {};
|
|
36
|
-
const { services,
|
|
36
|
+
const { services, hostedZoneId } = args;
|
|
37
37
|
this.name = name;
|
|
38
38
|
this.hostedZoneId = hostedZoneId;
|
|
39
|
-
this.environment = environment;
|
|
40
39
|
this.vpc = this.createVpc();
|
|
41
40
|
this.createServices(services);
|
|
42
41
|
if (args.enableSSMConnect) {
|
|
@@ -82,7 +81,9 @@ class Project extends pulumi.ComponentResource {
|
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
83
|
createWebServerPrerequisites() {
|
|
85
|
-
this.cluster = new aws.ecs.Cluster(`${this.name}-cluster`, {
|
|
84
|
+
this.cluster = new aws.ecs.Cluster(`${this.name}-cluster`, {
|
|
85
|
+
name: this.name,
|
|
86
|
+
}, { parent: this });
|
|
86
87
|
}
|
|
87
88
|
createDatabaseService(options) {
|
|
88
89
|
const { serviceName, type } = options, databaseOptions = __rest(options, ["serviceName", "type"]);
|
|
@@ -11,6 +11,12 @@ export type StaticSiteArgs = {
|
|
|
11
11
|
* The ID of the hosted zone.
|
|
12
12
|
*/
|
|
13
13
|
hostedZoneId: pulumi.Input<string>;
|
|
14
|
+
/**
|
|
15
|
+
* A map of tags to assign to the resource.
|
|
16
|
+
*/
|
|
17
|
+
tags?: pulumi.Input<{
|
|
18
|
+
[key: string]: pulumi.Input<string>;
|
|
19
|
+
}>;
|
|
14
20
|
};
|
|
15
21
|
export declare class StaticSite extends pulumi.ComponentResource {
|
|
16
22
|
certificate: AcmCertificate;
|
|
@@ -17,6 +17,7 @@ class StaticSite extends pulumi.ComponentResource {
|
|
|
17
17
|
indexDocument: 'index.html',
|
|
18
18
|
errorDocument: 'index.html',
|
|
19
19
|
},
|
|
20
|
+
tags: args.tags,
|
|
20
21
|
}, { parent: this });
|
|
21
22
|
const bucketPublicAccessBlock = new aws.s3.BucketPublicAccessBlock(`${name}-bucket-access-block`, {
|
|
22
23
|
bucket: bucket.id,
|
|
@@ -86,6 +87,7 @@ class StaticSite extends pulumi.ComponentResource {
|
|
|
86
87
|
restrictions: {
|
|
87
88
|
geoRestriction: { restrictionType: 'none' },
|
|
88
89
|
},
|
|
90
|
+
tags: args.tags,
|
|
89
91
|
}, { parent: this });
|
|
90
92
|
const cdnAliasRecord = new aws.route53.Record(`${name}-cdn-route53-record`, {
|
|
91
93
|
type: 'A',
|
|
@@ -70,6 +70,12 @@ export type WebServerArgs = {
|
|
|
70
70
|
healtCheckPath?: pulumi.Input<string>;
|
|
71
71
|
taskExecutionRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
72
72
|
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
73
|
+
/**
|
|
74
|
+
* A map of tags to assign to the resource.
|
|
75
|
+
*/
|
|
76
|
+
tags?: pulumi.Input<{
|
|
77
|
+
[key: string]: pulumi.Input<string>;
|
|
78
|
+
}>;
|
|
73
79
|
};
|
|
74
80
|
export declare class WebServer extends pulumi.ComponentResource {
|
|
75
81
|
certificate: AcmCertificate;
|
|
@@ -138,7 +138,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
138
138
|
inlinePolicies: argsWithDefaults.taskExecutionRoleInlinePolicies,
|
|
139
139
|
}, { parent: this });
|
|
140
140
|
const execCmdInlinePolicy = {
|
|
141
|
-
name:
|
|
141
|
+
name: `${name}-ecs-exec`,
|
|
142
142
|
policy: JSON.stringify({
|
|
143
143
|
Version: '2012-10-17',
|
|
144
144
|
Statement: [
|
|
@@ -219,6 +219,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
219
219
|
},
|
|
220
220
|
]);
|
|
221
221
|
}),
|
|
222
|
+
tags: argsWithDefaults.tags,
|
|
222
223
|
}, { parent: this });
|
|
223
224
|
this.serviceSecurityGroup = new aws.ec2.SecurityGroup(`${name}-security-group`, {
|
|
224
225
|
vpcId: argsWithDefaults.vpc.vpcId,
|
|
@@ -258,6 +259,7 @@ class WebServer extends pulumi.ComponentResource {
|
|
|
258
259
|
subnets: argsWithDefaults.vpc.publicSubnetIds,
|
|
259
260
|
securityGroups: [this.serviceSecurityGroup.id],
|
|
260
261
|
},
|
|
262
|
+
tags: argsWithDefaults.tags,
|
|
261
263
|
}, {
|
|
262
264
|
parent: this,
|
|
263
265
|
dependsOn: [
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PredefinedSize = void 0;
|
|
4
4
|
const CPU_1_VCPU = 1024;
|
|
5
5
|
const MEMORY_1GB = 1024;
|
|
6
6
|
exports.PredefinedSize = {
|
|
@@ -21,7 +21,3 @@ exports.PredefinedSize = {
|
|
|
21
21
|
memory: MEMORY_1GB * 4, // 4 GB memory
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
|
-
exports.Environment = {
|
|
25
|
-
DEVELOPMENT: 'DEVELOPMENT',
|
|
26
|
-
PRODUCTION: 'PRODUCTION',
|
|
27
|
-
};
|