-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstance.ts
45 lines (39 loc) · 1.71 KB
/
instance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { InstanceType } from "@aws-cdk/aws-ec2";
import type { CfnDBInstance, DatabaseInstanceProps, IParameterGroup } from "@aws-cdk/aws-rds";
import { DatabaseInstance, ParameterGroup } from "@aws-cdk/aws-rds";
import { Fn } from "@aws-cdk/core";
import type { GuStack } from "../core";
import { AppIdentity } from "../core/identity";
export interface GuDatabaseInstanceProps extends Omit<DatabaseInstanceProps, "instanceType">, AppIdentity {
overrideId?: boolean;
instanceType: string;
parameters?: Record<string, string>;
}
export class GuDatabaseInstance extends DatabaseInstance {
constructor(scope: GuStack, id: string, props: GuDatabaseInstanceProps) {
// CDK just wants "t3.micro" format, whereas
// some CFN yaml might have the older "db.t3.micro" with the "db." prefix
// This logic ensures the "db." prefix is removed before applying the CFN
const instanceType = new InstanceType(Fn.join("", Fn.split("db.", props.instanceType)));
let parameterGroup: IParameterGroup | undefined;
if (props.parameterGroup) {
parameterGroup = props.parameterGroup;
} else if (props.parameters) {
parameterGroup = new ParameterGroup(scope, `${id}-RDSParameterGroup`, {
engine: props.engine,
parameters: props.parameters,
});
}
super(scope, id, {
deletionProtection: true,
...props,
instanceType,
...(parameterGroup && { parameterGroup }),
});
if (props.overrideId || (scope.migratedFromCloudFormation && props.overrideId !== false)) {
(this.node.defaultChild as CfnDBInstance).overrideLogicalId(id);
}
parameterGroup && AppIdentity.taggedConstruct(props, parameterGroup);
AppIdentity.taggedConstruct(props, this);
}
}