-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDbResource.js
72 lines (57 loc) · 2.21 KB
/
DbResource.js
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
const pulumi = require('@pulumi/pulumi');
const aws = require('@pulumi/aws');
const { toBoolean, toNumber } = require('./utils');
class DbResource extends pulumi.ComponentResource {
constructor(name, args, opts = {}) {
const {
vpcSecurityGroupIds,
} = args;
super('resource:group:DbResource', name, args, opts);
const dbConfig = new pulumi.Config('db');
const username = dbConfig.requireSecret('user');
const password = dbConfig.requireSecret('pass');
const engine = dbConfig.require('engine');
const engineVersion = dbConfig.require('engineVersion');
const instanceClass = dbConfig.require('instanceClass');
const allocatedStorage = toNumber(dbConfig.require('allocatedStorage'));
const maxAllocatedStorage = toNumber(dbConfig.require('maxAllocatedStorage'));
const storageType = dbConfig.require('storageType');
const parameterGroupName = dbConfig.require('engineGroupName');
const backupRetentionPeriod = toNumber(dbConfig.require('backupRetentionPeriod'));
const backupWindow = dbConfig.require('backupWindow');
const deleteAutomatedBackups = toBoolean(dbConfig.require('deleteAutomatedBackups'));
const deletionProtection = toBoolean(dbConfig.require('deletionProtection'));
const finalSnapshotIdentifier = dbConfig.require('finalSnapshotIdentifier');
const skipFinalSnapshot = toBoolean(dbConfig.require('skipFinalSnapshot'));
const databaseName = dbConfig.require('databaseName');
if (username && password && databaseName) {
const instance = new aws.rds.Instance(name, {
name: databaseName,
username,
password,
allocatedStorage,
// auto storage scale
maxAllocatedStorage,
engine,
engineVersion,
instanceClass,
parameterGroupName,
storageType,
backupRetentionPeriod,
backupWindow,
deleteAutomatedBackups,
deletionProtection,
finalSnapshotIdentifier,
skipFinalSnapshot,
vpcSecurityGroupIds,
copyTagsToSnapshot: true,
applyImmediately: true,
});
this.instance = instance;
this.registerOutputs({
instance,
});
}
}
}
module.exports = DbResource;