UNPKG

@studion/infra-code-blocks

Version:
98 lines (97 loc) 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatabaseBuilder = void 0; const _1 = require("."); const pulumi = require("@pulumi/pulumi"); class DatabaseBuilder { name; instanceConfig; credentialsConfig; storageConfig; vpc; enableMonitoring; snapshotIdentifier; kmsKeyId; parameterGroupName; tags; replicaConfigs = new Map(); enableSSMConnect; ssmConnectConfig; constructor(name) { this.name = name; } withInstance(instanceConfig = {}) { this.instanceConfig = instanceConfig; return this; } withCredentials(credentialsConfig = {}) { this.credentialsConfig = credentialsConfig; return this; } withStorage(storageConfig = {}) { this.storageConfig = storageConfig; return this; } withVpc(vpc) { this.vpc = pulumi.output(vpc); return this; } withMonitoring() { this.enableMonitoring = true; return this; } withSnapshot(snapshotIdentifier) { this.snapshotIdentifier = snapshotIdentifier; return this; } withKms(kmsKeyId) { this.kmsKeyId = kmsKeyId; return this; } withParameterGroup(parameterGroupName) { this.parameterGroupName = parameterGroupName; return this; } withTags(tags) { this.tags = tags; return this; } addReplica(name, replicaConfig = {}) { this.replicaConfigs.set(name, replicaConfig); return this; } withSSMConnect(ssmConnectConfig = {}) { this.enableSSMConnect = true; this.ssmConnectConfig = ssmConnectConfig; return this; } build(opts = {}) { if (this.replicaConfigs?.size) { this.replicaConfigs.forEach(config => { if (config.enableMonitoring && !this.enableMonitoring && !config.monitoringRole) { throw new Error('To enable replica monitoring, either provide a monitoring role or enable primary instance monitoring.'); } }); } if (!this.vpc) { throw new Error('VPC not provided. Make sure to call DatabaseBuilder.withVpc().'); } return new _1.Database(this.name, { ...this.instanceConfig, ...this.credentialsConfig, ...this.storageConfig, vpc: this.vpc, enableMonitoring: this.enableMonitoring, snapshotIdentifier: this.snapshotIdentifier, kmsKeyId: this.kmsKeyId, parameterGroupName: this.parameterGroupName, tags: this.tags, replicaConfigs: this.replicaConfigs, enableSSMConnect: this.enableSSMConnect, ssmConnectConfig: this.ssmConnectConfig, }, opts); } } exports.DatabaseBuilder = DatabaseBuilder;