Skip to content

Commit

Permalink
feat: Default to GP3 storage type (#2522)
Browse files Browse the repository at this point in the history
marsavar authored Dec 4, 2024
1 parent 49d4e0f commit bf08a5e
Showing 3 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-scissors-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/cdk": minor
---

Default to GP3 storage type for RDS
39 changes: 38 additions & 1 deletion src/constructs/rds/instance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Duration, Stack } from "aws-cdk-lib";
import { Match, Template } from "aws-cdk-lib/assertions";
import { Vpc } from "aws-cdk-lib/aws-ec2";
import { DatabaseInstanceEngine, PostgresEngineVersion } from "aws-cdk-lib/aws-rds";
import { DatabaseInstanceEngine, PostgresEngineVersion, StorageType } from "aws-cdk-lib/aws-rds";
import { GuTemplate, simpleGuStackForTesting } from "../../utils/test";
import { GuDatabaseInstance } from "./instance";

@@ -147,4 +147,41 @@ describe("The GuDatabaseInstance class", () => {
PreferredBackupWindow: "00:00-02:00",
});
});

test("defaults to GP3 storage type", () => {
const stack = simpleGuStackForTesting();
new GuDatabaseInstance(stack, "DatabaseInstance", {
vpc,
instanceType: "t3.small",
engine: DatabaseInstanceEngine.postgres({
version: PostgresEngineVersion.VER_16,
}),
app: "testing",
devXBackups: {
enabled: true,
},
});
Template.fromStack(stack).hasResourceProperties("AWS::RDS::DBInstance", {
StorageType: "gp3",
});
});

test("uses the specified storage type when the default is overridden", () => {
const stack = simpleGuStackForTesting();
new GuDatabaseInstance(stack, "DatabaseInstance", {
vpc,
instanceType: "t3.small",
engine: DatabaseInstanceEngine.postgres({
version: PostgresEngineVersion.VER_16,
}),
app: "testing",
devXBackups: {
enabled: true,
},
storageType: StorageType.GP2, // ← Overriding default storage type here
});
Template.fromStack(stack).hasResourceProperties("AWS::RDS::DBInstance", {
StorageType: "gp2",
});
});
});
3 changes: 2 additions & 1 deletion src/constructs/rds/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fn, Tags } from "aws-cdk-lib";
import { InstanceType } from "aws-cdk-lib/aws-ec2";
import { DatabaseInstance } from "aws-cdk-lib/aws-rds";
import { DatabaseInstance, StorageType } from "aws-cdk-lib/aws-rds";
import type { DatabaseInstanceProps } from "aws-cdk-lib/aws-rds";
import { GuAppAwareConstruct } from "../../utils/mixin/app-aware-construct";
import type { AppIdentity, GuStack } from "../core";
@@ -39,6 +39,7 @@ export class GuDatabaseInstance extends GuAppAwareConstruct(DatabaseInstance) {
const instanceType = new InstanceType(Fn.join("", Fn.split("db.", props.instanceType)));

super(scope, id, {
storageType: StorageType.GP3,
deletionProtection: true,
deleteAutomatedBackups: false,
backupRetention: props.devXBackups.enabled ? undefined : props.devXBackups.backupRetention,

0 comments on commit bf08a5e

Please sign in to comment.