@studion/infra-code-blocks 0.3.0 → 0.4.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
@@ -372,7 +372,7 @@ type DatabaseArgs = {
372
372
 
373
373
  If the password is not specified it will be autogenerated.
374
374
  The database password is stored as a secret inside AWS Secret Manager.
375
- The secret will be available on the `Database` resource as `passwordSecret`.
375
+ The secret will be available on the `Database` resource as `password.secret`.
376
376
 
377
377
  ### Redis
378
378
 
@@ -600,7 +600,7 @@ export type MongoArgs = {
600
600
 
601
601
  If the password is not specified it will be autogenerated.
602
602
  The mongo password is stored as a secret inside AWS Secret Manager.
603
- The secret will be available on the `Mongo` resource as `passwordSecret`.
603
+ The secret will be available on the `Mongo` resource as `password.secret`.
604
604
 
605
605
  ### Ecs Service
606
606
 
@@ -1,5 +1,6 @@
1
1
  import * as aws from '@pulumi/aws';
2
2
  import * as pulumi from '@pulumi/pulumi';
3
+ import { Password } from './password';
3
4
  export type DatabaseArgs = {
4
5
  /**
5
6
  * The name of the database to create when the DB instance is created.
@@ -56,11 +57,10 @@ export declare class Database extends pulumi.ComponentResource {
56
57
  kms: aws.kms.Key;
57
58
  dbSubnetGroup: aws.rds.SubnetGroup;
58
59
  dbSecurityGroup: aws.ec2.SecurityGroup;
59
- passwordSecret: aws.secretsmanager.Secret;
60
+ password: Password;
60
61
  constructor(name: string, args: DatabaseArgs, opts?: pulumi.ComponentResourceOptions);
61
62
  private createSubnetGroup;
62
63
  private createSecurityGroup;
63
64
  private createEncryptionKey;
64
- private createPasswordSecret;
65
65
  private createDatabaseInstance;
66
66
  }
@@ -3,7 +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
+ const password_1 = require("./password");
7
7
  const constants_1 = require("../constants");
8
8
  const defaults = {
9
9
  applyImmediately: false,
@@ -20,9 +20,8 @@ class Database extends pulumi.ComponentResource {
20
20
  this.dbSubnetGroup = this.createSubnetGroup({ isolatedSubnetIds });
21
21
  this.dbSecurityGroup = this.createSecurityGroup({ vpcId, vpcCidrBlock });
22
22
  this.kms = this.createEncryptionKey();
23
- const { instance, passwordSecret } = this.createDatabaseInstance(args);
24
- this.instance = instance;
25
- this.passwordSecret = passwordSecret;
23
+ this.password = new password_1.Password(`${this.name}-database-password`, { value: args.password }, { parent: this });
24
+ this.instance = this.createDatabaseInstance(args);
26
25
  this.registerOutputs();
27
26
  }
28
27
  createSubnetGroup({ isolatedSubnetIds, }) {
@@ -59,29 +58,9 @@ class Database extends pulumi.ComponentResource {
59
58
  }, { parent: this });
60
59
  return kms;
61
60
  }
62
- createPasswordSecret({ password }) {
63
- const project = pulumi.getProject();
64
- const stack = pulumi.getStack();
65
- const passwordSecret = new aws.secretsmanager.Secret(`${this.name}-password-secret`, {
66
- namePrefix: `${stack}/${project}/DatabasePassword-`,
67
- tags: constants_1.commonTags,
68
- }, { parent: this });
69
- const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${this.name}-password-secret-value`, {
70
- secretId: passwordSecret.id,
71
- secretString: password,
72
- }, { parent: this, dependsOn: [passwordSecret] });
73
- return passwordSecret;
74
- }
75
61
  createDatabaseInstance(args) {
76
62
  const argsWithDefaults = Object.assign({}, defaults, args);
77
63
  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 });
85
64
  const instance = new aws.rds.Instance(`${this.name}-rds`, {
86
65
  identifierPrefix: `${this.name}-`,
87
66
  engine: 'postgres',
@@ -91,7 +70,7 @@ class Database extends pulumi.ComponentResource {
91
70
  instanceClass: argsWithDefaults.instanceClass,
92
71
  dbName: argsWithDefaults.dbName,
93
72
  username: argsWithDefaults.username,
94
- password,
73
+ password: this.password.value,
95
74
  dbSubnetGroupName: this.dbSubnetGroup.name,
96
75
  vpcSecurityGroupIds: [this.dbSecurityGroup.id],
97
76
  storageEncrypted: true,
@@ -105,8 +84,8 @@ class Database extends pulumi.ComponentResource {
105
84
  backupWindow: '06:00-06:30',
106
85
  backupRetentionPeriod: 14,
107
86
  tags: Object.assign(Object.assign({}, constants_1.commonTags), argsWithDefaults.tags),
108
- }, { parent: this });
109
- return { instance, passwordSecret };
87
+ }, { parent: this, dependsOn: [this.password] });
88
+ return instance;
110
89
  }
111
90
  }
112
91
  exports.Database = Database;
@@ -1,6 +1,6 @@
1
1
  import * as pulumi from '@pulumi/pulumi';
2
- import * as aws from '@pulumi/aws';
3
2
  import { EcsService, EcsServiceArgs } from './ecs-service';
3
+ import { Password } from './password';
4
4
  export type MongoArgs = Pick<EcsServiceArgs, 'size' | 'clusterId' | 'clusterName' | 'vpcId' | 'vpcCidrBlock' | 'tags'> & {
5
5
  /**
6
6
  * Username for the master DB user.
@@ -20,8 +20,6 @@ export type MongoArgs = Pick<EcsServiceArgs, 'size' | 'clusterId' | 'clusterName
20
20
  export declare class Mongo extends pulumi.ComponentResource {
21
21
  name: string;
22
22
  service: EcsService;
23
- passwordSecret: aws.secretsmanager.Secret;
23
+ password: Password;
24
24
  constructor(name: string, args: MongoArgs, opts?: pulumi.ComponentResourceOptions);
25
- private createRandomPassword;
26
- private createPasswordSecret;
27
25
  }
@@ -13,18 +13,15 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.Mongo = void 0;
15
15
  const pulumi = require("@pulumi/pulumi");
16
- const aws = require("@pulumi/aws");
17
- const random = require("@pulumi/random");
18
- const constants_1 = require("../constants");
19
16
  const ecs_service_1 = require("./ecs-service");
17
+ const password_1 = require("./password");
20
18
  class Mongo extends pulumi.ComponentResource {
21
19
  constructor(name, args, opts = {}) {
22
20
  super('studion:Mongo', name, args, opts);
23
21
  const port = args.port || 27017;
24
22
  const { username, password, privateSubnetIds } = args, ecsServiceArgs = __rest(args, ["username", "password", "privateSubnetIds"]);
25
23
  this.name = name;
26
- const mongoPassword = password || this.createRandomPassword();
27
- this.passwordSecret = this.createPasswordSecret(mongoPassword);
24
+ this.password = new password_1.Password(`${this.name}-mongo-password`, { value: password }, { parent: this });
28
25
  this.service = new ecs_service_1.EcsService(name, Object.assign(Object.assign({}, ecsServiceArgs), { port, image: 'mongo:7.0.3@sha256:238b1636bdd7820c752b91bec8a669f92568eb313ad89a1fc4a92903c1b40489', desiredCount: 1, autoscaling: { enabled: false }, enableServiceAutoDiscovery: true, persistentStorageVolumePath: '/data/db', dockerCommand: ['mongod', '--port', port.toString()], assignPublicIp: false, subnetIds: privateSubnetIds, environment: [
29
26
  {
30
27
  name: 'MONGO_INITDB_ROOT_USERNAME',
@@ -33,31 +30,10 @@ class Mongo extends pulumi.ComponentResource {
33
30
  ], secrets: [
34
31
  {
35
32
  name: 'MONGO_INITDB_ROOT_PASSWORD',
36
- valueFrom: this.passwordSecret.arn,
33
+ valueFrom: this.password.secret.arn,
37
34
  },
38
35
  ] }), Object.assign(Object.assign({}, opts), { parent: this }));
39
36
  this.registerOutputs();
40
37
  }
41
- createRandomPassword() {
42
- const password = new random.RandomPassword(`${this.name}-mongo-password`, {
43
- length: 16,
44
- overrideSpecial: '_%$',
45
- special: true,
46
- });
47
- return password.result;
48
- }
49
- createPasswordSecret(password) {
50
- const project = pulumi.getProject();
51
- const stack = pulumi.getStack();
52
- const passwordSecret = new aws.secretsmanager.Secret(`${this.name}-password-secret`, {
53
- namePrefix: `${stack}/${project}/MongoPassword-`,
54
- tags: constants_1.commonTags,
55
- }, { parent: this });
56
- const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${this.name}-password-secret-value`, {
57
- secretId: passwordSecret.id,
58
- secretString: password,
59
- }, { parent: this, dependsOn: [passwordSecret] });
60
- return passwordSecret;
61
- }
62
38
  }
63
39
  exports.Mongo = Mongo;
@@ -0,0 +1,12 @@
1
+ import * as aws from '@pulumi/aws';
2
+ import * as pulumi from '@pulumi/pulumi';
3
+ export type PasswordArgs = {
4
+ value?: pulumi.Input<string>;
5
+ };
6
+ export declare class Password extends pulumi.ComponentResource {
7
+ name: string;
8
+ value: pulumi.Output<string>;
9
+ secret: aws.secretsmanager.Secret;
10
+ constructor(name: string, args: PasswordArgs, opts?: pulumi.ComponentResourceOptions);
11
+ private createPasswordSecret;
12
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Password = void 0;
4
+ const aws = require("@pulumi/aws");
5
+ const pulumi = require("@pulumi/pulumi");
6
+ const random = require("@pulumi/random");
7
+ const constants_1 = require("../constants");
8
+ class Password extends pulumi.ComponentResource {
9
+ constructor(name, args, opts = {}) {
10
+ const optsWithDefauls = pulumi.mergeOptions(opts, {
11
+ additionalSecretOutputs: ['value'],
12
+ });
13
+ super('studion:Password', name, {}, optsWithDefauls);
14
+ this.name = name;
15
+ if (args.value) {
16
+ this.value = pulumi.output(args.value);
17
+ }
18
+ else {
19
+ const password = new random.RandomPassword(`${this.name}-random-password`, {
20
+ length: 16,
21
+ overrideSpecial: '_%$',
22
+ special: true,
23
+ }, { parent: this });
24
+ this.value = password.result;
25
+ }
26
+ this.secret = this.createPasswordSecret(this.value);
27
+ this.registerOutputs();
28
+ }
29
+ createPasswordSecret(password) {
30
+ const project = pulumi.getProject();
31
+ const stack = pulumi.getStack();
32
+ const passwordSecret = new aws.secretsmanager.Secret(`${this.name}-password-secret`, {
33
+ namePrefix: `${stack}/${project}/${this.name}-`,
34
+ tags: constants_1.commonTags,
35
+ }, { parent: this });
36
+ const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${this.name}-password-secret-value`, {
37
+ secretId: passwordSecret.id,
38
+ secretString: password,
39
+ }, { parent: this, dependsOn: [passwordSecret] });
40
+ return passwordSecret;
41
+ }
42
+ }
43
+ exports.Password = Password;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studion/infra-code-blocks",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Studion common infra components",
5
5
  "keywords": [
6
6
  "infrastructure",