Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"prettier": "@studion/prettier-config",
"dependencies": {
"@pulumi/aws": "^7.23.0",
"@pulumi/aws-native": "^1.57.0",
"@pulumi/awsx": "^3.3.0",
"@pulumi/pulumi": "^3.226.0",
"@pulumi/random": "^4.19.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/database/database-replica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class DatabaseReplica extends pulumi.ComponentResource {
applyImmediately: argsWithDefaults.applyImmediately,
allowMajorVersionUpgrade: argsWithDefaults.allowMajorVersionUpgrade,
autoMinorVersionUpgrade: argsWithDefaults.autoMinorVersionUpgrade,
maintenanceWindow: 'Mon:07:00-Mon:07:30',
replicateSourceDb: argsWithDefaults.replicateSourceDb,
parameterGroupName: argsWithDefaults.parameterGroupName,
storageEncrypted: true,
Expand Down
45 changes: 22 additions & 23 deletions src/components/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as aws from '@pulumi/aws';
import * as awsNative from '@pulumi/aws-native';
import * as awsx from '@pulumi/awsx';
import * as pulumi from '@pulumi/pulumi';
import { commonTags } from '../../shared/common-tags';
Expand All @@ -17,6 +16,7 @@ export namespace Database {
allowMajorVersionUpgrade?: pulumi.Input<boolean>;
autoMinorVersionUpgrade?: pulumi.Input<boolean>;
applyImmediately?: pulumi.Input<boolean>;
skipFinalSnapshot?: pulumi.Input<boolean>;
};

export type Credentials = {
Expand Down Expand Up @@ -66,6 +66,7 @@ export namespace Database {
const defaults = {
multiAz: false,
applyImmediately: false,
skipFinalSnapshot: false,
allocatedStorage: 20,
maxAllocatedStorage: 100,
instanceClass: 'db.t4g.micro',
Expand All @@ -77,7 +78,7 @@ const defaults = {

export class Database extends pulumi.ComponentResource {
name: string;
instance: awsNative.rds.DbInstance;
instance: aws.rds.Instance;
vpc: pulumi.Output<awsx.ec2.Vpc>;
dbSubnetGroup: aws.rds.SubnetGroup;
dbSecurityGroup: aws.ec2.SecurityGroup;
Expand Down Expand Up @@ -262,7 +263,7 @@ export class Database extends pulumi.ComponentResource {
const replica = new DatabaseReplica(
`${this.name}-replica`,
{
replicateSourceDb: this.instance.dbInstanceIdentifier.apply(id => id!),
replicateSourceDb: this.instance.identifier.apply(id => id!),
dbSecurityGroup: this.dbSecurityGroup,
monitoringRole,
...config,
Expand All @@ -285,29 +286,31 @@ export class Database extends pulumi.ComponentResource {
}

private createDatabaseInstance(args: Database.Args) {
const stack = pulumi.getStack();

const monitoringOptions =
args.enableMonitoring && this.monitoringRole
? {
monitoringInterval: 60,
monitoringRoleArn: this.monitoringRole.arn,
enablePerformanceInsights: true,
performanceInsightsEnabled: true,
performanceInsightsRetentionPeriod: 7,
}
: {};

const instance = new awsNative.rds.DbInstance(
const instance = new aws.rds.Instance(
`${this.name}-rds`,
{
dbInstanceIdentifier: `${this.name}-db-instance`,
identifierPrefix: `${this.name}-`,
engine: 'postgres',
engineVersion: args.engineVersion,
dbInstanceClass: args.instanceClass,
instanceClass: args.instanceClass!,
dbName: args.dbName,
masterUsername: args.username,
masterUserPassword: this.password.value,
username: args.username,
password: this.password.value,
dbSubnetGroupName: this.dbSubnetGroup.name,
vpcSecurityGroups: [this.dbSecurityGroup.id],
allocatedStorage: args.allocatedStorage?.toString(),
vpcSecurityGroupIds: [this.dbSecurityGroup.id],
allocatedStorage: args.allocatedStorage,
maxAllocatedStorage: args.maxAllocatedStorage,
multiAz: args.multiAz,
applyImmediately: args.applyImmediately,
Expand All @@ -316,21 +319,17 @@ export class Database extends pulumi.ComponentResource {
kmsKeyId: this.kmsKeyId,
storageEncrypted: true,
publiclyAccessible: false,
preferredMaintenanceWindow: 'Mon:07:00-Mon:07:30',
preferredBackupWindow: '06:00-06:30',
skipFinalSnapshot: args.skipFinalSnapshot,
maintenanceWindow: 'Mon:07:00-Mon:07:30',
finalSnapshotIdentifier: `${this.name}-final-snapshot-${stack}`,
backupWindow: '06:00-06:30',
backupRetentionPeriod: 14,
caCertificateIdentifier: 'rds-ca-rsa2048-g1',
dbParameterGroupName: args.parameterGroupName,
dbSnapshotIdentifier:
caCertIdentifier: 'rds-ca-rsa2048-g1',
parameterGroupName: args.parameterGroupName,
snapshotIdentifier:
this.encryptedSnapshotCopy?.targetDbSnapshotIdentifier,
...monitoringOptions,
tags: pulumi
.output(args.tags)
.apply(tags => [
...Object.entries({ ...commonTags, ...tags }).map(
([key, value]) => ({ key, value }),
),
]),
tags: { ...commonTags, ...args.tags },
},
{ parent: this, dependsOn: [this.password] },
);
Expand Down
21 changes: 13 additions & 8 deletions tests/database/configurable-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
assert.ok(configurableDb.instance, 'Database instance should be defined');

const command = new DescribeDBInstancesCommand({
DBInstanceIdentifier: configurableDb.instance.dbInstanceIdentifier,
DBInstanceIdentifier: configurableDb.instance.identifier,
});

const { DBInstances } = await ctx.clients.rds.send(command);
Expand All @@ -34,7 +34,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
const [DBInstance] = DBInstances;
assert.strictEqual(
DBInstance.DBInstanceIdentifier,
configurableDb.instance.dbInstanceIdentifier,
configurableDb.instance.identifier,
'Database instance identifier should match',
);
});
Expand All @@ -57,16 +57,21 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
ctx.config.autoMinorVersionUpgrade,
'Auto minor version upgrade argument should be set correctly',
);
assert.strictEqual(
configurableDb.instance.skipFinalSnapshot,
ctx.config.skipFinalSnapshot,
'Skip final snapshot argument should be set correctly',
);
});

it('should properly configure password', () => {
const configurableDb = ctx.outputs.configurableDb.value;

assert.ok(configurableDb.password, 'Password should exist');
assert.strictEqual(
configurableDb.instance.masterUserPassword,
configurableDb.instance.password,
ctx.config.dbPassword,
'Master user password should be set correctly',
'Password should be set correctly',
);
});

Expand All @@ -75,7 +80,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {

assert.strictEqual(
configurableDb.instance.allocatedStorage,
ctx.config.allocatedStorage.toString(),
ctx.config.allocatedStorage,
'Allocated storage argument should be set correctly',
);
assert.strictEqual(
Expand All @@ -89,7 +94,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
const configurableDb = ctx.outputs.configurableDb.value;

assert.strictEqual(
configurableDb.instance.enablePerformanceInsights,
configurableDb.instance.performanceInsightsEnabled,
true,
'Performance insights should be enabled',
);
Expand Down Expand Up @@ -152,7 +157,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
const paramGroup = ctx.outputs.paramGroup.value;

assert.strictEqual(
configurableDb.instance.dbParameterGroupName,
configurableDb.instance.parameterGroupName,
paramGroup.name,
'Parameter group name should be set correctly',
);
Expand All @@ -162,7 +167,7 @@ export function testConfigurableDb(ctx: DatabaseTestContext) {
const configurableDb = ctx.outputs.configurableDb.value;

const command = new ListTagsForResourceCommand({
ResourceName: configurableDb.instance.dbInstanceArn,
ResourceName: configurableDb.instance.arn,
});
const { TagList } = await ctx.clients.rds.send(command);
assert.ok(TagList && TagList.length > 0, 'Tags should exist');
Expand Down
6 changes: 3 additions & 3 deletions tests/database/configurable-replica-db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { it } from 'node:test';
export function testConfigurableReplica(ctx: DatabaseTestContext) {
it('should create a primary instance with a configurable replica', async () => {
const configurableReplicaDb = ctx.outputs.configurableReplicaDb.value;
const { dbInstanceIdentifier } = configurableReplicaDb.instance;
const { identifier } = configurableReplicaDb.instance;

const command = new DescribeDBInstancesCommand({
DBInstanceIdentifier: dbInstanceIdentifier,
DBInstanceIdentifier: identifier,
});

const { DBInstances } = await ctx.clients.rds.send(command);
assert.ok(
DBInstances &&
DBInstances.length === 1 &&
DBInstances[0].DBInstanceIdentifier === dbInstanceIdentifier,
DBInstances[0].DBInstanceIdentifier === identifier,
'Primary database instance should be created',
);
});
Expand Down
15 changes: 6 additions & 9 deletions tests/database/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cleanupReplicas, cleanupSnapshots } from './util';
import { describe, before, after } from 'node:test';
import {
DescribeDBInstancesCommand,
Expand Down Expand Up @@ -55,9 +54,7 @@ describe('Database component deployment', () => {
});

after(async () => {
await cleanupReplicas(ctx);
await automation.destroy(programArgs);
await cleanupSnapshots(ctx);
});

it('should create a database', async () => {
Expand All @@ -72,7 +69,7 @@ describe('Database component deployment', () => {
assert.ok(database.instance, 'Database instance should be defined');

const command = new DescribeDBInstancesCommand({
DBInstanceIdentifier: database.instance.dbInstanceIdentifier,
DBInstanceIdentifier: database.instance.identifier,
});

const { DBInstances } = await ctx.clients.rds.send(command);
Expand All @@ -83,7 +80,7 @@ describe('Database component deployment', () => {
const [DBInstance] = DBInstances;
assert.strictEqual(
DBInstance.DBInstanceIdentifier,
database.instance.dbInstanceIdentifier,
database.instance.identifier,
'Database instance identifier should match',
);
});
Expand All @@ -104,13 +101,13 @@ describe('Database component deployment', () => {
instance,
{
dbName: ctx.config.dbName,
masterUsername: ctx.config.dbUsername,
username: ctx.config.dbUsername,
multiAz: false,
applyImmediately: false,
allocatedStorage: '20',
allocatedStorage: 20,
maxAllocatedStorage: 100,
dbInstanceClass: 'db.t4g.micro',
enablePerformanceInsights: false,
instanceClass: 'db.t4g.micro',
performanceInsightsEnabled: false,
allowMajorVersionUpgrade: false,
autoMinorVersionUpgrade: true,
engineVersion: '17.2',
Expand Down
1 change: 1 addition & 0 deletions tests/database/infrastructure/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const dbPassword = 'dbpassword';
export const applyImmediately = true;
export const allowMajorVersionUpgrade = true;
export const autoMinorVersionUpgrade = false;
export const skipFinalSnapshot = true;
export const allocatedStorage = 10;
export const maxAllocatedStorage = 50;
Loading