diff --git a/.changeset/soft-scissors-turn.md b/.changeset/soft-scissors-turn.md new file mode 100644 index 0000000000..fd0c3f1f12 --- /dev/null +++ b/.changeset/soft-scissors-turn.md @@ -0,0 +1,5 @@ +--- +"@guardian/cdk": minor +--- + +Default to GP3 storage type for RDS diff --git a/src/constructs/rds/instance.test.ts b/src/constructs/rds/instance.test.ts index f78bb2ad9f..546af11001 100644 --- a/src/constructs/rds/instance.test.ts +++ b/src/constructs/rds/instance.test.ts @@ -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", + }); + }); }); diff --git a/src/constructs/rds/instance.ts b/src/constructs/rds/instance.ts index 69a2ba8e08..c9011f53e2 100644 --- a/src/constructs/rds/instance.ts +++ b/src/constructs/rds/instance.ts @@ -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,