Skip to content

Commit 447cc67

Browse files
committed
Allow major version upgrades to be configurable from args, remove random sufix
1 parent 0a4baec commit 447cc67

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/components/database.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as aws from '@pulumi/aws';
22
import * as pulumi from '@pulumi/pulumi';
3-
import * as random from '@pulumi/random';
43
import { Password } from './password';
54
import { commonTags } from '../constants';
65

@@ -55,6 +54,11 @@ export type DatabaseArgs = {
5554
* Set this to true to enable database monitoring. Defaults to false.
5655
*/
5756
enableMonitoring?: pulumi.Input<boolean>;
57+
/**
58+
* Set this to true to allow major version upgrades, for example when creating
59+
* db from the snapshot. Defaults to false.
60+
*/
61+
allowMajorVersionUpgrade?: pulumi.Input<boolean>;
5862
/**
5963
* The name of custom aws.rds.ParameterGroup. Setting this param will apply custom
6064
* DB parameters to this instance.
@@ -82,6 +86,7 @@ const defaults = {
8286
maxAllocatedStorage: 100,
8387
instanceClass: 'db.t4g.micro',
8488
enableMonitoring: false,
89+
allowMajorVersionUpgrade: false,
8590
};
8691

8792
export class Database extends pulumi.ComponentResource {
@@ -216,20 +221,11 @@ export class Database extends pulumi.ComponentResource {
216221
private createEncryptedSnapshotCopy(
217222
snapshotIdentifier: NonNullable<DatabaseArgs['snapshotIdentifier']>,
218223
) {
219-
const targetDbSnapshotIdentifier = new random.RandomString(
220-
`${this.name}-snapshot-copy-identifier-sufix`,
221-
{
222-
length: 10,
223-
special: false,
224-
},
225-
{ parent: this },
226-
).result.apply(sufix => `${snapshotIdentifier}-${sufix}`);
227-
228224
const encryptedSnapshotCopy = new aws.rds.SnapshotCopy(
229225
`${this.name}-encrypted-snapshot-copy`,
230226
{
231227
sourceDbSnapshotIdentifier: snapshotIdentifier,
232-
targetDbSnapshotIdentifier,
228+
targetDbSnapshotIdentifier: `${snapshotIdentifier}-encrypted-copy`,
233229
kmsKeyId: this.kms.arn,
234230
},
235231
{ parent: this },
@@ -278,7 +274,7 @@ export class Database extends pulumi.ComponentResource {
278274
backupRetentionPeriod: 14,
279275
caCertIdentifier: 'rds-ca-rsa2048-g1',
280276
parameterGroupName: argsWithDefaults.parameterGroupName,
281-
allowMajorVersionUpgrade: Boolean(argsWithDefaults.snapshotIdentifier),
277+
allowMajorVersionUpgrade: argsWithDefaults.allowMajorVersionUpgrade,
282278
snapshotIdentifier:
283279
this.encryptedSnapshotCopy?.targetDbSnapshotIdentifier,
284280
...monitoringOptions,

0 commit comments

Comments
 (0)