@studion/infra-code-blocks 0.5.2 → 0.6.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
CHANGED
|
@@ -12,7 +12,7 @@ Studion Platform common infra components.
|
|
|
12
12
|
## Prerequisites
|
|
13
13
|
|
|
14
14
|
- Working [Pulumi](https://www.pulumi.com/docs/clouds/aws/get-started/begin/#pulumi-aws-before-you-begin) project
|
|
15
|
-
- AWS account with
|
|
15
|
+
- AWS account with necessary permissions for each Studion component
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -48,7 +48,7 @@ const project = new studion.Project('demo-project', {
|
|
|
48
48
|
export const projectName = project.name;
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
- Deploy
|
|
51
|
+
- Deploy Pulumi stack
|
|
52
52
|
|
|
53
53
|
```bash
|
|
54
54
|
$ pulumi up
|
|
@@ -68,10 +68,14 @@ $ pulumi up
|
|
|
68
68
|
|
|
69
69
|
### Project
|
|
70
70
|
|
|
71
|
-
Project component makes it
|
|
71
|
+
Project component makes it easy to spin up project infrastructure,
|
|
72
72
|
hiding infrastructure complexity.
|
|
73
73
|
<br>
|
|
74
|
-
The component creates its own VPC
|
|
74
|
+
The component creates its own VPC used for resources within the project.
|
|
75
|
+
<br><br>
|
|
76
|
+
Services are created only if specified in the `services` list.
|
|
77
|
+
<br>
|
|
78
|
+
If `services` is an empty list, VPC is the only service created by default.
|
|
75
79
|
|
|
76
80
|
```ts
|
|
77
81
|
new Project(name: string, args: ProjectArgs, opts?: pulumi.CustomResourceOptions);
|
|
@@ -102,7 +106,7 @@ type ProjectArgs = {
|
|
|
102
106
|
| Argument | Description |
|
|
103
107
|
| :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
104
108
|
| services \* | Service list. |
|
|
105
|
-
| enableSSMConnect |
|
|
109
|
+
| enableSSMConnect | Set up 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. |
|
|
106
110
|
| numberOfAvailabilityZones | Default is 2 which is recommended. If building a dev server, we can reduce to 1 availability zone to reduce hosting cost. |
|
|
107
111
|
|
|
108
112
|
```ts
|
|
@@ -257,7 +261,7 @@ type EcsServiceOptions = {
|
|
|
257
261
|
|
|
258
262
|
Often, web server depends on other services such as database, Redis, etc.
|
|
259
263
|
For that purpose, environment factory can be used. The factory function
|
|
260
|
-
|
|
264
|
+
receives services bag as argument.
|
|
261
265
|
|
|
262
266
|
```ts
|
|
263
267
|
const project = new studion.Project('demo-project', {
|
|
@@ -287,7 +291,7 @@ const project = new studion.Project('demo-project', {
|
|
|
287
291
|
});
|
|
288
292
|
```
|
|
289
293
|
|
|
290
|
-
In order to pass sensitive information to the container use `secrets` instead of `environment`. AWS will fetch values from
|
|
294
|
+
In order to pass sensitive information to the container, use `secrets` instead of `environment`. AWS will fetch values from
|
|
291
295
|
Secret Manager based on arn that is provided for the `valueFrom` field.
|
|
292
296
|
|
|
293
297
|
```ts
|
|
@@ -379,7 +383,7 @@ type DatabaseArgs = {
|
|
|
379
383
|
};
|
|
380
384
|
```
|
|
381
385
|
|
|
382
|
-
If the password is not specified it will be autogenerated.
|
|
386
|
+
If the password is not specified, it will be autogenerated.
|
|
383
387
|
The database password is stored as a secret inside AWS Secret Manager.
|
|
384
388
|
The secret will be available on the `Database` resource as `password.secret`.
|
|
385
389
|
|
|
@@ -407,8 +411,8 @@ new DatabaseReplica(name: string, args: DatabaseReplicaArgs, opts?: pulumi.Custo
|
|
|
407
411
|
```ts
|
|
408
412
|
type DatabaseReplicaArgs = {
|
|
409
413
|
replicateSourceDb: pulumi.Input<string>;
|
|
410
|
-
dbSubnetGroupName: pulumi.Input<string>;
|
|
411
414
|
dbSecurityGroupId: pulumi.Input<string>;
|
|
415
|
+
dbSubnetGroupName?: pulumi.Input<string>;
|
|
412
416
|
monitoringRole?: aws.iam.Role;
|
|
413
417
|
multiAz?: pulumi.Input<boolean>;
|
|
414
418
|
applyImmediately?: pulumi.Input<boolean>;
|
|
@@ -421,7 +425,15 @@ type DatabaseReplicaArgs = {
|
|
|
421
425
|
}>;
|
|
422
426
|
};
|
|
423
427
|
```
|
|
424
|
-
Database replica requires primary DB instance to exist.
|
|
428
|
+
Database replica requires primary DB instance to exist. If the replica is in the same
|
|
429
|
+
region as primary instance, we should not set `dbSubnetGroupNameParam`.
|
|
430
|
+
The `replicateSourceDb` param is referenced like this:
|
|
431
|
+
```javascript
|
|
432
|
+
const primaryDb = new studion.Database(...);
|
|
433
|
+
const replica = new studion.DatabaseReplica('replica', {
|
|
434
|
+
replicateSourceDb: primaryDb.instance.identifier
|
|
435
|
+
});
|
|
436
|
+
```
|
|
425
437
|
|
|
426
438
|
### Redis
|
|
427
439
|
|
|
@@ -510,7 +522,7 @@ Features:
|
|
|
510
522
|
- creates TLS certificate for the specified domain
|
|
511
523
|
- redirects HTTP traffic to HTTPS
|
|
512
524
|
- creates CloudWatch log group
|
|
513
|
-
- comes with predefined
|
|
525
|
+
- comes with predefined CPU and memory options: `small`, `medium`, `large`, `xlarge`
|
|
514
526
|
|
|
515
527
|
<br>
|
|
516
528
|
|
|
@@ -565,7 +577,7 @@ Features:
|
|
|
565
577
|
- creates TLS certificate for the specified domain
|
|
566
578
|
- redirects HTTP traffic to HTTPS
|
|
567
579
|
- creates CloudWatch log group
|
|
568
|
-
- comes with predefined
|
|
580
|
+
- comes with predefined CPU and memory options: `small`, `medium`, `large`, `xlarge`
|
|
569
581
|
- CDN in front of the application load balancer for static resource caching
|
|
570
582
|
|
|
571
583
|
<br>
|
|
@@ -616,7 +628,7 @@ Features:
|
|
|
616
628
|
- persistent storage
|
|
617
629
|
- service auto-discovery
|
|
618
630
|
- creates CloudWatch log group
|
|
619
|
-
- comes with predefined
|
|
631
|
+
- comes with predefined CPU and memory options: `small`, `medium`, `large`, `xlarge`
|
|
620
632
|
|
|
621
633
|
<br>
|
|
622
634
|
|
|
@@ -648,7 +660,7 @@ export type MongoArgs = {
|
|
|
648
660
|
```
|
|
649
661
|
|
|
650
662
|
If the password is not specified it will be autogenerated.
|
|
651
|
-
The
|
|
663
|
+
The Mongo password is stored as a secret inside AWS Secret Manager.
|
|
652
664
|
The secret will be available on the `Mongo` resource as `password.secret`.
|
|
653
665
|
|
|
654
666
|
### Ecs Service
|
|
@@ -658,7 +670,7 @@ AWS ECS Fargate.
|
|
|
658
670
|
Features:
|
|
659
671
|
|
|
660
672
|
- memory and CPU autoscaling
|
|
661
|
-
- service auto
|
|
673
|
+
- service auto-discovery
|
|
662
674
|
- persistent storage
|
|
663
675
|
- CloudWatch logs
|
|
664
676
|
- comes with predefined cpu and memory options: `small`, `medium`, `large`, `xlarge`
|
|
@@ -739,7 +751,7 @@ Where `CLUSTER_NAME` is the name of the ECS cluster and `TASK_FAMILY_NAME` is th
|
|
|
739
751
|
|
|
740
752
|
## SSM Connect
|
|
741
753
|
|
|
742
|
-
The [Database](#database) component deploys a database instance inside
|
|
754
|
+
The [Database](#database) component deploys a database instance inside an isolated subnet,
|
|
743
755
|
and it's not publicly accessible from outside of VPC.
|
|
744
756
|
<br>
|
|
745
757
|
In order to connect to the database we need to deploy the ec2 instance which will be used
|
|
@@ -788,7 +800,7 @@ Now you can use your favorite database client to connect to the database.
|
|
|
788
800
|

|
|
789
801
|
|
|
790
802
|
It is important that for the host you set `localhost` and for the port you set `5555`
|
|
791
|
-
because we are port
|
|
803
|
+
because we are port-forwarding traffic from
|
|
792
804
|
localhost:5555 to DATABASE_ADDRESS:DATABASE_PORT.
|
|
793
805
|
For the user, password, and database field, set values which are set in the `Project`.
|
|
794
806
|
|
|
@@ -10,7 +10,7 @@ export type DatabaseReplicaArgs = {
|
|
|
10
10
|
* * If primary DB is instance of studion:Database, it can be accessed as
|
|
11
11
|
* `db.dbSubnetGroup.name`.
|
|
12
12
|
*/
|
|
13
|
-
dbSubnetGroupName
|
|
13
|
+
dbSubnetGroupName?: pulumi.Input<string>;
|
|
14
14
|
/**
|
|
15
15
|
* DB security group ID. Should be the same as primary instance.
|
|
16
16
|
* If primary DB is instance of studion:Database, it can be accessed as
|
|
@@ -96,7 +96,7 @@ class Database extends pulumi.ComponentResource {
|
|
|
96
96
|
performanceInsightsRetentionPeriod: 7,
|
|
97
97
|
}
|
|
98
98
|
: {};
|
|
99
|
-
const instance = new aws.rds.Instance(`${this.name}-rds`, Object.assign(Object.assign({ identifierPrefix: `${this.name}-`, engine: 'postgres', engineVersion: '15.5', allocatedStorage: argsWithDefaults.allocatedStorage, maxAllocatedStorage: argsWithDefaults.maxAllocatedStorage, instanceClass: argsWithDefaults.instanceClass, dbName: argsWithDefaults.dbName, username: argsWithDefaults.username, password: this.password.value, dbSubnetGroupName: this.dbSubnetGroup.name, vpcSecurityGroupIds: [this.dbSecurityGroup.id], storageEncrypted: true, kmsKeyId: this.kms.arn, multiAz: argsWithDefaults.multiAz, publiclyAccessible: false, skipFinalSnapshot: argsWithDefaults.skipFinalSnapshot, applyImmediately: argsWithDefaults.applyImmediately, autoMinorVersionUpgrade: true, maintenanceWindow: 'Mon:07:00-Mon:07:30', finalSnapshotIdentifier: `${this.name}-final-snapshot-${stack}`, backupWindow: '06:00-06:30', backupRetentionPeriod: 14, parameterGroupName: argsWithDefaults.parameterGroupName }, monitoringOptions), { tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags) }), { parent: this, dependsOn: [this.password] });
|
|
99
|
+
const instance = new aws.rds.Instance(`${this.name}-rds`, Object.assign(Object.assign({ identifierPrefix: `${this.name}-`, engine: 'postgres', engineVersion: '15.5', allocatedStorage: argsWithDefaults.allocatedStorage, maxAllocatedStorage: argsWithDefaults.maxAllocatedStorage, instanceClass: argsWithDefaults.instanceClass, dbName: argsWithDefaults.dbName, username: argsWithDefaults.username, password: this.password.value, dbSubnetGroupName: this.dbSubnetGroup.name, vpcSecurityGroupIds: [this.dbSecurityGroup.id], storageEncrypted: true, kmsKeyId: this.kms.arn, multiAz: argsWithDefaults.multiAz, publiclyAccessible: false, skipFinalSnapshot: argsWithDefaults.skipFinalSnapshot, applyImmediately: argsWithDefaults.applyImmediately, autoMinorVersionUpgrade: true, maintenanceWindow: 'Mon:07:00-Mon:07:30', finalSnapshotIdentifier: `${this.name}-final-snapshot-${stack}`, backupWindow: '06:00-06:30', backupRetentionPeriod: 14, caCertIdentifier: 'rds-ca-rsa2048-g1', parameterGroupName: argsWithDefaults.parameterGroupName }, monitoringOptions), { tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags) }), { parent: this, dependsOn: [this.password] });
|
|
100
100
|
return instance;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -2,6 +2,7 @@ import * as pulumi from '@pulumi/pulumi';
|
|
|
2
2
|
import { EcsService, EcsServiceArgs } from './ecs-service';
|
|
3
3
|
import { Password } from './password';
|
|
4
4
|
export type MongoArgs = Pick<EcsServiceArgs, 'size' | 'clusterId' | 'clusterName' | 'vpcId' | 'vpcCidrBlock' | 'tags'> & {
|
|
5
|
+
privateSubnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
5
6
|
/**
|
|
6
7
|
* Username for the master DB user.
|
|
7
8
|
*/
|
|
@@ -11,11 +12,18 @@ export type MongoArgs = Pick<EcsServiceArgs, 'size' | 'clusterId' | 'clusterName
|
|
|
11
12
|
* The value will be stored as a secret in AWS Secret Manager.
|
|
12
13
|
*/
|
|
13
14
|
password?: pulumi.Input<string>;
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Mongo Docker image. Defaults to mongo:7.0.3.
|
|
17
|
+
*/
|
|
18
|
+
image?: pulumi.Input<string>;
|
|
15
19
|
/**
|
|
16
20
|
* Exposed service port. Defaults to 27017.
|
|
17
21
|
*/
|
|
18
22
|
port?: pulumi.Input<number>;
|
|
23
|
+
/**
|
|
24
|
+
* Persistent storage volume path. Defaults to '/data/db'.
|
|
25
|
+
*/
|
|
26
|
+
persistentStorageVolumePath?: pulumi.Input<string>;
|
|
19
27
|
};
|
|
20
28
|
export declare class Mongo extends pulumi.ComponentResource {
|
|
21
29
|
name: string;
|
package/dist/components/mongo.js
CHANGED
|
@@ -18,11 +18,15 @@ const password_1 = require("./password");
|
|
|
18
18
|
class Mongo extends pulumi.ComponentResource {
|
|
19
19
|
constructor(name, args, opts = {}) {
|
|
20
20
|
super('studion:Mongo', name, args, opts);
|
|
21
|
+
const image = args.image ||
|
|
22
|
+
'mongo:7.0.3@sha256:238b1636bdd7820c752b91bec8a669f92568eb313ad89a1fc4a92903c1b40489';
|
|
21
23
|
const port = args.port || 27017;
|
|
24
|
+
const persistentStorageVolumePath = args.persistentStorageVolumePath || '/data/db';
|
|
22
25
|
const { username, password, privateSubnetIds } = args, ecsServiceArgs = __rest(args, ["username", "password", "privateSubnetIds"]);
|
|
23
26
|
this.name = name;
|
|
24
27
|
this.password = new password_1.Password(`${this.name}-mongo-password`, { value: password }, { parent: this });
|
|
25
|
-
this.service = new ecs_service_1.EcsService(name, Object.assign(Object.assign({}, ecsServiceArgs), { port,
|
|
28
|
+
this.service = new ecs_service_1.EcsService(name, Object.assign(Object.assign({}, ecsServiceArgs), { port,
|
|
29
|
+
image, desiredCount: 1, autoscaling: { enabled: false }, enableServiceAutoDiscovery: true, persistentStorageVolumePath, dockerCommand: ['mongod', '--port', port.toString()], assignPublicIp: false, subnetIds: privateSubnetIds, environment: [
|
|
26
30
|
{
|
|
27
31
|
name: 'MONGO_INITDB_ROOT_USERNAME',
|
|
28
32
|
value: username,
|