@@ -25,11 +25,6 @@ export interface PgBouncerConfigProps {
25
25
}
26
26
27
27
export interface PgBouncerProps {
28
- /**
29
- * Name for the pgbouncer instance
30
- */
31
- instanceName : string ;
32
-
33
28
/**
34
29
* VPC to deploy PgBouncer into
35
30
*/
@@ -56,15 +51,14 @@ export interface PgBouncerProps {
56
51
usePublicSubnet ?: boolean ;
57
52
58
53
/**
59
- * Instance type for PgBouncer
60
- * @default t3.micro
54
+ * PgBouncer configuration options
61
55
*/
62
- instanceType ?: ec2 . InstanceType ;
56
+ pgBouncerConfig ?: PgBouncerConfigProps ;
63
57
64
58
/**
65
- * PgBouncer configuration options
59
+ * EC2 instance options
66
60
*/
67
- pgBouncerConfig ?: PgBouncerConfigProps ;
61
+ instanceProps ?: Partial < ec2 . InstanceProps > ;
68
62
}
69
63
70
64
export class PgBouncer extends Construct {
@@ -78,7 +72,7 @@ export class PgBouncer extends Construct {
78
72
// be slightly smaller than the actual max_connections value on the RDS instance
79
73
// so we perform this calculation.
80
74
81
- private getDefaultConfig (
75
+ private getDefaultPgbouncerConfig (
82
76
dbMaxConnections : number
83
77
) : Required < PgBouncerConfigProps > {
84
78
// maxDbConnections (and maxUserConnections) are the only settings that need
@@ -99,17 +93,14 @@ export class PgBouncer extends Construct {
99
93
super ( scope , id ) ;
100
94
101
95
// Set defaults for optional props
102
- const defaultInstanceType = ec2 . InstanceType . of (
103
- ec2 . InstanceClass . T3 ,
104
- ec2 . InstanceSize . MICRO
105
- ) ;
106
96
107
- const instanceType = props . instanceType ?? defaultInstanceType ;
108
- const defaultConfig = this . getDefaultConfig ( props . dbMaxConnections ) ;
97
+ const defaultPgbouncerConfig = this . getDefaultPgbouncerConfig (
98
+ props . dbMaxConnections
99
+ ) ;
109
100
110
101
// Merge provided config with defaults
111
102
const pgBouncerConfig : Required < PgBouncerConfigProps > = {
112
- ...defaultConfig ,
103
+ ...defaultPgbouncerConfig ,
113
104
...props . pgBouncerConfig ,
114
105
} ;
115
106
@@ -144,21 +135,21 @@ export class PgBouncer extends Construct {
144
135
} ) ;
145
136
146
137
// Create PgBouncer instance
147
- this . instance = new ec2 . Instance ( this , "Instance" , {
148
- vpc : props . vpc ,
138
+ const defaultInstanceConfig : Omit < ec2 . InstanceProps , "vpc" > = {
139
+ instanceName : "pgbouncer" ,
140
+ instanceType : ec2 . InstanceType . of (
141
+ ec2 . InstanceClass . T3 ,
142
+ ec2 . InstanceSize . MICRO
143
+ ) ,
149
144
vpcSubnets : {
150
145
subnetType : props . usePublicSubnet
151
146
? ec2 . SubnetType . PUBLIC
152
147
: ec2 . SubnetType . PRIVATE_WITH_EGRESS ,
153
148
} ,
154
- securityGroup : this . securityGroup ,
155
- instanceType,
156
- instanceName : props . instanceName ,
157
149
machineImage : ec2 . MachineImage . fromSsmParameter (
158
150
"/aws/service/canonical/ubuntu/server/jammy/stable/current/amd64/hvm/ebs-gp2/ami-id" ,
159
151
{ os : ec2 . OperatingSystemType . LINUX }
160
152
) ,
161
- role,
162
153
blockDevices : [
163
154
{
164
155
deviceName : "/dev/xvda" ,
@@ -169,9 +160,17 @@ export class PgBouncer extends Construct {
169
160
} ) ,
170
161
} ,
171
162
] ,
163
+ role,
164
+ securityGroup : this . securityGroup ,
172
165
userData : this . loadUserDataScript ( pgBouncerConfig , props . database ) ,
173
166
userDataCausesReplacement : true ,
174
167
associatePublicIpAddress : props . usePublicSubnet ,
168
+ } ;
169
+
170
+ this . instance = new ec2 . Instance ( this , "Instance" , {
171
+ ...defaultInstanceConfig ,
172
+ ...props . instanceProps ,
173
+ vpc : props . vpc ,
175
174
} ) ;
176
175
177
176
// Allow PgBouncer to connect to RDS
@@ -183,7 +182,7 @@ export class PgBouncer extends Construct {
183
182
184
183
// Create a new secret for pgbouncer connection credentials
185
184
this . pgbouncerSecret = new secretsmanager . Secret ( this , "PgBouncerSecret" , {
186
- description : ` Connection information for PgBouncer instance ${ props . instanceName } ` ,
185
+ description : " Connection information for PgBouncer instance" ,
187
186
generateSecretString : {
188
187
generateStringKey : "dummy" ,
189
188
secretStringTemplate : "{}" ,
0 commit comments