Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aacc229
Create db v2 component
mandryllo Dec 2, 2025
ccdc0da
Remove ability to create custom parameter group
mandryllo Dec 5, 2025
08829e0
Cleanup
mandryllo Dec 5, 2025
003dbc2
Fix kms key id type
mandryllo Dec 5, 2025
ceb3a78
Cleanup
mandryllo Dec 5, 2025
7cbd0b6
Cleanup vpc parameters
mandryllo Dec 5, 2025
96e1045
Cleanup types
mandryllo Dec 5, 2025
41465b4
Fix formatting
mandryllo Dec 5, 2025
e9b7ea6
Cleanup
mandryllo Dec 8, 2025
d08a2f0
Create db builder component
mandryllo Dec 2, 2025
e200c4b
Fix typo
mandryllo Dec 3, 2025
d7a4436
Remove custom parameter group args
mandryllo Dec 5, 2025
1e447d8
Cleanup private props
mandryllo Dec 5, 2025
5ec7516
Remove parameter group name from builder
mandryllo Dec 5, 2025
9a8f476
Cleanup naming
mandryllo Dec 5, 2025
d1470a6
Fix formatting
mandryllo Dec 5, 2025
0406006
Cleanup
mandryllo Dec 8, 2025
4c9c426
Cleanup database types
mandryllo Dec 10, 2025
d067ec5
Cleanup
mandryllo Dec 10, 2025
31cbcd1
Revert allocatedStorage type to number
mandryllo Dec 10, 2025
d94a98e
Remove withKms method from builder
mandryllo Dec 10, 2025
b64d94c
fix tags
mandryllo Dec 10, 2025
62206a3
Fix snapshot id
mandryllo Dec 10, 2025
a77022b
Fix wrong condition
mandryllo Dec 11, 2025
02235d5
Update database builder
mandryllo Dec 16, 2025
63c1af7
Cleanup
mandryllo Dec 16, 2025
78c8231
Move applyImmediately to instance config
mandryllo Dec 16, 2025
3137cdd
Update builder methods
mandryllo Dec 16, 2025
da11c61
Move kms key from storage type
mandryllo Dec 16, 2025
390c04d
Update builder
mandryllo Dec 16, 2025
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
121 changes: 121 additions & 0 deletions src/v2/components/database/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { Database } from '.';
import * as pulumi from '@pulumi/pulumi';

export class DatabaseBuilder {
private name: string;
private instanceConfig?: Database.Instance;
private credentialsConfig?: Database.Credentials;
private storageConfig?: Database.Storage;
private vpc?: Database.Args['vpc'];
private enableMonitoring?: Database.Args['enableMonitoring'];
private snapshotIdentifier?: Database.Args['snapshotIdentifier'];
private kmsKeyId?: Database.Args['kmsKeyId'];
private parameterGroupName?: Database.Args['parameterGroupName'];
private tags?: Database.Args['tags'];

constructor(name: string) {
this.name = name;
}

public withInstance(instanceConfig: Database.Instance = {}): this {
this.instanceConfig = instanceConfig;

return this;
}

public withCredentials(credentialsConfig: Database.Credentials = {}): this {
this.credentialsConfig = credentialsConfig;

return this;
}

public withStorage(storageConfig: Database.Storage = {}): this {
this.storageConfig = storageConfig;

return this;
}

public withVpc(vpc: Database.Args['vpc']): this {
this.vpc = pulumi.output(vpc);

return this;
}

public withMonitoring(): this {
this.enableMonitoring = true;

return this;
}

public withSnapshot(
snapshotIdentifier: Database.Args['snapshotIdentifier'],
): this {
this.snapshotIdentifier = snapshotIdentifier;

return this;
}

public withKms(kmsKeyId: Database.Args['kmsKeyId']): this {
this.kmsKeyId = kmsKeyId;

return this;
}

public withParameterGroup(
parameterGroupName: Database.Args['parameterGroupName'],
): this {
this.parameterGroupName = parameterGroupName;

return this;
}

public withTags(tags: Database.Args['tags']): this {
this.tags = tags;

return this;
}

public build(opts: pulumi.ComponentResourceOptions = {}): Database {
if (!this.snapshotIdentifier && !this.instanceConfig?.dbName) {
throw new Error(
'DbName not provided. Make sure to call DatabaseBuilder.withInstance() and set dbName.',
);
}

if (!this.snapshotIdentifier && !this.credentialsConfig?.username) {
throw new Error(
'Username not provided. Make sure to call DatabaseBuilder.withCredentials() and set username.',
);
}

if (this.snapshotIdentifier && this.instanceConfig?.dbName) {
throw new Error(`You can't set dbName when using snapshotIdentifier.`);
}

if (this.snapshotIdentifier && this.credentialsConfig?.username) {
throw new Error(`You can't set username when using snapshotIdentifier.`);
}

if (!this.vpc) {
throw new Error(
'VPC not provided. Make sure to call DatabaseBuilder.withVpc().',
);
}

return new 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,
},
opts,
);
}
}
4 changes: 2 additions & 2 deletions src/v2/components/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export namespace Database {
instanceClass?: pulumi.Input<string>;
allowMajorVersionUpgrade?: pulumi.Input<boolean>;
autoMinorVersionUpgrade?: pulumi.Input<boolean>;
applyImmediately?: pulumi.Input<boolean>;
};

export type Credentials = {
Expand All @@ -23,17 +24,16 @@ export namespace Database {
export type Storage = {
allocatedStorage?: pulumi.Input<number>;
maxAllocatedStorage?: pulumi.Input<number>;
kmsKeyId?: pulumi.Input<string>;
};

export type Args = Instance &
Credentials &
Storage & {
vpc: pulumi.Input<awsx.ec2.Vpc>;
enableMonitoring?: pulumi.Input<boolean>;
applyImmediately?: pulumi.Input<boolean>;
snapshotIdentifier?: pulumi.Input<string>;
parameterGroupName?: pulumi.Input<string>;
kmsKeyId?: pulumi.Input<string>;
tags?: pulumi.Input<{
[key: string]: pulumi.Input<string>;
}>;
Expand Down