@digitraffic/common 2025.1.10-1 → 2025.1.15-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
|
|
1
1
|
import { type InstanceType, type ISecurityGroup, type IVpc } from "aws-cdk-lib/aws-ec2";
|
2
2
|
import { type AuroraPostgresEngineVersion, DatabaseCluster, type DatabaseClusterProps, type IParameterGroup } from "aws-cdk-lib/aws-rds";
|
3
|
+
import { Stack } from "aws-cdk-lib/core";
|
3
4
|
import type { Construct } from "constructs/lib/construct.js";
|
4
5
|
import type { InfraStackConfiguration } from "./intra-stack-configuration.js";
|
5
|
-
import { Stack } from "aws-cdk-lib/core";
|
6
6
|
export interface DbConfiguration {
|
7
7
|
readonly cluster?: ClusterConfiguration;
|
8
8
|
readonly clusterImport?: ClusterImportConfiguration;
|
@@ -15,13 +15,16 @@ export interface DbConfiguration {
|
|
15
15
|
/** If this is not specified, import default vpc */
|
16
16
|
readonly vpc?: IVpc;
|
17
17
|
}
|
18
|
+
export interface ClusterDbInstanceConfiguration {
|
19
|
+
readonly instanceType: InstanceType;
|
20
|
+
readonly isFromLegacyInstanceProps?: boolean;
|
21
|
+
}
|
18
22
|
export interface ClusterConfiguration {
|
19
23
|
readonly securityGroupId: string;
|
20
|
-
readonly dbInstanceType: InstanceType;
|
21
24
|
readonly snapshotIdentifier?: string;
|
22
|
-
readonly instances: number;
|
23
25
|
readonly dbVersion: AuroraPostgresEngineVersion;
|
24
|
-
readonly
|
26
|
+
readonly writer: ClusterDbInstanceConfiguration;
|
27
|
+
readonly readers: ClusterDbInstanceConfiguration[];
|
25
28
|
}
|
26
29
|
export interface ClusterImportConfiguration {
|
27
30
|
readonly clusterReadEndpoint: string;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { SecurityGroup, SubnetType, } from "aws-cdk-lib/aws-ec2";
|
2
|
-
import { CfnDBInstance, Credentials, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot, InstanceUpdateBehaviour, ParameterGroup, } from "aws-cdk-lib/aws-rds";
|
2
|
+
import { CfnDBInstance, ClusterInstance, Credentials, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot, InstanceUpdateBehaviour, ParameterGroup, } from "aws-cdk-lib/aws-rds";
|
3
3
|
import { Secret } from "aws-cdk-lib/aws-secretsmanager";
|
4
|
-
import { exportValue, importVpc } from "../import-util.js";
|
5
4
|
import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib/core";
|
5
|
+
import { exportValue, importVpc } from "../import-util.js";
|
6
6
|
import { createParameter } from "../stack/parameters.js";
|
7
7
|
/**
|
8
8
|
* Stack that creates DatabaseCluster.
|
@@ -64,11 +64,37 @@ export class DbStack extends Stack {
|
|
64
64
|
}
|
65
65
|
createClusterParameters(secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroup) {
|
66
66
|
const secret = Secret.fromSecretCompleteArn(this, "DBSecret", secretArn);
|
67
|
+
const defaultDbInstanceProps = {
|
68
|
+
autoMinorVersionUpgrade: true,
|
69
|
+
allowMajorVersionUpgrade: false,
|
70
|
+
enablePerformanceInsights: true,
|
71
|
+
parameterGroup: parameterGroup
|
72
|
+
};
|
73
|
+
const writer = ClusterInstance.provisioned("WriterInstance", {
|
74
|
+
...{
|
75
|
+
instanceType: clusterConfiguration.writer.instanceType,
|
76
|
+
isFromLegacyInstanceProps: clusterConfiguration.writer.isFromLegacyInstanceProps
|
77
|
+
},
|
78
|
+
...defaultDbInstanceProps
|
79
|
+
});
|
80
|
+
const readers = clusterConfiguration.readers.map((reader, index) => ClusterInstance.provisioned(`ReaderInstance${index}`, {
|
81
|
+
...{
|
82
|
+
instanceType: reader.instanceType,
|
83
|
+
isFromLegacyInstanceProps: reader.isFromLegacyInstanceProps,
|
84
|
+
},
|
85
|
+
...defaultDbInstanceProps
|
86
|
+
}));
|
67
87
|
return {
|
68
88
|
engine: DatabaseClusterEngine.auroraPostgres({
|
69
89
|
version: clusterConfiguration.dbVersion,
|
70
90
|
}),
|
71
|
-
|
91
|
+
writer,
|
92
|
+
readers,
|
93
|
+
vpcSubnets: {
|
94
|
+
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
|
95
|
+
},
|
96
|
+
securityGroups: [securityGroup],
|
97
|
+
vpc,
|
72
98
|
instanceUpdateBehaviour: InstanceUpdateBehaviour.ROLLING,
|
73
99
|
instanceIdentifierBase: instanceName + "-",
|
74
100
|
cloudwatchLogsExports: ["postgresql"],
|
@@ -80,21 +106,8 @@ export class DbStack extends Stack {
|
|
80
106
|
deletionProtection: true,
|
81
107
|
removalPolicy: RemovalPolicy.RETAIN,
|
82
108
|
port: DbStack.CLUSTER_PORT,
|
83
|
-
instanceProps: {
|
84
|
-
autoMinorVersionUpgrade: true,
|
85
|
-
allowMajorVersionUpgrade: false,
|
86
|
-
enablePerformanceInsights: true,
|
87
|
-
vpc,
|
88
|
-
securityGroups: [securityGroup],
|
89
|
-
vpcSubnets: {
|
90
|
-
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
|
91
|
-
},
|
92
|
-
instanceType: clusterConfiguration.dbInstanceType,
|
93
|
-
parameterGroup,
|
94
|
-
},
|
95
109
|
credentials: Credentials.fromPassword(secret.secretValueFromJson("db.superuser").unsafeUnwrap(), secret.secretValueFromJson("db.superuser.password")),
|
96
110
|
parameterGroup,
|
97
|
-
// storageEncrypted: clusterConfiguration.storageEncrypted ?? true,
|
98
111
|
monitoringInterval: Duration.seconds(30),
|
99
112
|
};
|
100
113
|
}
|
@@ -116,10 +129,13 @@ export class DbStack extends Stack {
|
|
116
129
|
})
|
117
130
|
: new DatabaseCluster(this, instanceName, parameters);
|
118
131
|
// this workaround should prevent stack failing on version upgrade
|
132
|
+
// https://github.com/aws/aws-cdk/issues/21758
|
133
|
+
// https://github.com/aws/aws-cdk/pull/22185
|
134
|
+
// Maybe this could be removed completely as we don't update db with the CDK?
|
119
135
|
const cfnInstances = cluster.node.children.filter((child) => child instanceof CfnDBInstance);
|
120
|
-
if (cfnInstances.length === 0) {
|
121
|
-
|
122
|
-
}
|
136
|
+
// if (cfnInstances.length === 0) {
|
137
|
+
// throw new Error("Couldn't pull CfnDBInstances from the L1 constructs!");
|
138
|
+
// }
|
123
139
|
cfnInstances.forEach((cfnInstance) => delete cfnInstance.engineVersion);
|
124
140
|
return cluster;
|
125
141
|
}
|