@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 700 lines 23.9 KB
Raw
1 import { MigrationError, type MigrationsInput } from "@alchemy.run/sql/Migrations";
2 import type { Input } from "alchemy/Input";
3 import * as Namespace from "alchemy/Namespace";
4 import { toWireSeconds } from "alchemy/Util/Duration";
5 import type * as Duration from "effect/Duration";
6 import * as Effect from "effect/Effect";
7 import * as Redacted from "effect/Redacted";
8 import type { SecurityGroupId } from "../EC2/SecurityGroup.ts";
9 import type { SubnetId } from "../EC2/Subnet.ts";
10 import * as IAM from "../IAM/index.ts";
11 import {
12 Secret,
13 type GenerateSecretStringProps,
14 type SecretProps,
15 type Secret as SecretResource,
16 } from "../SecretsManager/Secret.ts";
17 import {
18 DBCluster,
19 type DBClusterProps,
20 type DBCluster as DBClusterResource,
21 } from "./DBCluster.ts";
22 import {
23 DBClusterParameterGroup,
24 type DBClusterParameterGroupProps,
25 type DBClusterParameterGroup as DBClusterParameterGroupResource,
26 } from "./DBClusterParameterGroup.ts";
27 import {
28 DBInstance,
29 type DBInstanceProps,
30 type DBInstance as DBInstanceResource,
31 } from "./DBInstance.ts";
32 import {
33 DBParameterGroup,
34 type DBParameterGroupProps,
35 type DBParameterGroup as DBParameterGroupResource,
36 } from "./DBParameterGroup.ts";
37 import { DBProxy, type DBProxyProps, type DBProxy as DBProxyResource } from "./DBProxy.ts";
38 import {
39 DBProxyEndpoint,
40 type DBProxyEndpointProps,
41 type DBProxyEndpoint as DBProxyEndpointResource,
42 } from "./DBProxyEndpoint.ts";
43 import {
44 DBProxyTargetGroup,
45 type DBProxyTargetGroupProps,
46 type DBProxyTargetGroup as DBProxyTargetGroupResource,
47 } from "./DBProxyTargetGroup.ts";
48 import {
49 DBSubnetGroup,
50 type DBSubnetGroupProps,
51 type DBSubnetGroup as DBSubnetGroupResource,
52 } from "./DBSubnetGroup.ts";
53 import type { MigrationsTransport } from "./Migrations.ts";
54
55 export interface AuroraSecretProps extends Omit<
56 SecretProps,
57 "secretString" | "secretBinary" | "generateSecretString"
58 > {
59 /**
60 * Existing secret to reuse instead of creating one.
61 */
62 resource?: SecretResource;
63 /**
64 * Master username written into a generated secret payload.
65 * @default "app"
66 */
67 username?: string;
68 /**
69 * Optional explicit JSON/string secret payload.
70 */
71 secretString?: Redacted.Redacted<string>;
72 /**
73 * Optional explicit binary secret payload.
74 */
75 secretBinary?: Redacted.Redacted<Uint8Array<ArrayBufferLike>>;
76 /**
77 * Password generation settings for the created secret.
78 */
79 generateSecretString?: GenerateSecretStringProps;
80 }
81
82 export interface AuroraProxyProps extends Omit<
83 DBProxyProps,
84 "engineFamily" | "auth" | "roleArn" | "vpcSubnetIds"
85 > {
86 /**
87 * Override the default proxy auth config.
88 */
89 auth?: DBProxyProps["auth"];
90 /**
91 * Additional target-group configuration for the default proxy target group.
92 */
93 targetGroup?: Omit<DBProxyTargetGroupProps, "dbProxyName" | "dbClusterIdentifiers">;
94 /**
95 * Optional extra endpoint to create for the proxy.
96 * Use `true` for sensible defaults.
97 */
98 endpoint?: true | Omit<DBProxyEndpointProps, "dbProxyName" | "vpcSubnetIds">;
99 }
100
101 export interface AuroraProps {
102 /**
103 * Database name created in the cluster.
104 * @default "app"
105 */
106 databaseName?: string;
107 /**
108 * Aurora engine.
109 * @default "aurora-postgresql"
110 */
111 engine?: string;
112 /**
113 * Optional engine version.
114 */
115 engineVersion?: string;
116 /**
117 * Subnets for the cluster and optional proxy.
118 */
119 subnetIds: Input<SubnetId[]>;
120 /**
121 * Security groups attached to the cluster and instance.
122 */
123 securityGroupIds: Input<SecurityGroupId[]>;
124 /**
125 * Number of read replicas to create alongside the writer.
126 * @default 0
127 */
128 readers?: number;
129 /**
130 * Cluster-wide tags applied to all created resources by default.
131 */
132 tags?: Record<string, Input<string>>;
133 /**
134 * Tune the generated or reused admin secret.
135 */
136 secret?: AuroraSecretProps;
137 /**
138 * Override subnet group creation.
139 */
140 subnetGroup?: Omit<DBSubnetGroupProps, "subnetIds">;
141 /**
142 * Optional cluster parameter group.
143 */
144 clusterParameterGroup?: Omit<DBClusterParameterGroupProps, "family"> & {
145 family: string;
146 };
147 /**
148 * Optional instance parameter group.
149 */
150 parameterGroup?: Omit<DBParameterGroupProps, "family"> & {
151 family: string;
152 };
153 /**
154 * Tune the Aurora cluster resource.
155 */
156 cluster?: Omit<
157 DBClusterProps,
158 | "engine"
159 | "engineVersion"
160 | "databaseName"
161 | "dbSubnetGroupName"
162 | "dbClusterParameterGroupName"
163 | "vpcSecurityGroupIds"
164 | "masterUserSecretArn"
165 | "masterUsername"
166 | "masterUserPassword"
167 | "tags"
168 > & {
169 tags?: Record<string, Input<string>>;
170 };
171 /**
172 * Tune the writer/readers.
173 */
174 instance?: Omit<
175 DBInstanceProps,
176 | "dbClusterIdentifier"
177 | "engine"
178 | "engineVersion"
179 | "dbSubnetGroupName"
180 | "dbParameterGroupName"
181 | "vpcSecurityGroupIds"
182 | "tags"
183 | "migrations"
184 | "migrationsTransport"
185 | "migrationsSecretArn"
186 > & {
187 tags?: Record<string, Input<string>>;
188 };
189 /**
190 * Whether to enable the Aurora Data API.
191 * @default true
192 */
193 dataApi?: boolean;
194 /**
195 * SQL migrations to apply to `databaseName` on deploy, once the writer is
196 * available. Accepts a directory path, a `Drizzle.Schema` resource, or
197 * `{ dir, table? }`.
198 *
199 * Bookkeeping always lives in Alchemy's `__alchemy_migrations` table. A
200 * database previously migrated by drizzle-kit or Prisma is adopted by a
201 * one-way conversion on first deploy. Over the Data API each statement is
202 * its own call: put each statement in its own file or separate statements
203 * with `--> statement-breakpoint` (drizzle-kit's default).
204 */
205 migrations?: Input<MigrationsInput>;
206 /**
207 * How `migrations` reach the cluster: `"data-api"`, `"direct"` (a
208 * connection from the deploying machine), or an `AWS.RDS.MigrationRunner`
209 * Lambda inside the VPC.
210 * @default "data-api" when `dataApi` is enabled, otherwise "direct"
211 */
212 migrationsTransport?: MigrationsTransport;
213 /**
214 * Backup retention period (e.g. `"7 days"`), forwarded to the cluster.
215 */
216 backupRetentionPeriod?: Duration.Input;
217 /**
218 * Daily backup window (`hh:mm-hh:mm` UTC), forwarded to the cluster.
219 */
220 preferredBackupWindow?: string;
221 /**
222 * Weekly maintenance window, forwarded to the cluster.
223 */
224 preferredMaintenanceWindow?: string;
225 /**
226 * Encrypt cluster storage. Forwarded to the cluster.
227 */
228 storageEncrypted?: boolean;
229 /**
230 * KMS key for storage encryption. Forwarded to the cluster.
231 */
232 kmsKeyId?: Input<string>;
233 /**
234 * Enable IAM database authentication. Forwarded to the cluster.
235 */
236 enableIAMDatabaseAuthentication?: boolean;
237 /**
238 * Log types to export to CloudWatch Logs. Forwarded to the cluster.
239 */
240 enableCloudwatchLogsExports?: string[];
241 /**
242 * Block accidental deletion. Forwarded to the cluster and instances.
243 * @default false
244 */
245 deletionProtection?: boolean;
246 /**
247 * CA certificate identifier. Forwarded to the cluster.
248 */
249 caCertificateIdentifier?: string;
250 /**
251 * Listener port. Forwarded to the cluster.
252 */
253 port?: number;
254 /**
255 * Aurora MySQL backtrack window (e.g. `"1 hour"`). Forwarded to the
256 * cluster.
257 */
258 backtrackWindow?: Duration.Input;
259 /**
260 * Enhanced-monitoring + Performance Insights settings. Forwarded to the
261 * cluster (and the enhanced-monitoring role to the instances).
262 */
263 monitoring?: {
264 /**
265 * Enhanced-monitoring granularity (e.g. `"60 seconds"`). Sent to the
266 * API in whole seconds (valid: 0, 1, 5, 10, 15, 30, 60).
267 */
268 interval?: Duration.Input;
269 /**
270 * Existing IAM role ARN for enhanced monitoring. When omitted and
271 * `interval > 0`, Aurora creates one automatically.
272 */
273 roleArn?: Input<string>;
274 /**
275 * Enable Performance Insights on the cluster.
276 */
277 performanceInsights?: boolean;
278 };
279 /**
280 * Serverless v2 min/max ACUs. Shorthand for
281 * `serverlessV2ScalingConfiguration`.
282 */
283 scaling?: {
284 minCapacity?: number;
285 maxCapacity?: number;
286 };
287 /**
288 * Provisioned (non-serverless) instance class for the writer/readers, e.g.
289 * `db.r6g.large`. Defaults to `db.serverless`.
290 */
291 instanceClass?: string;
292 /**
293 * Opt in to an auto-wired RDS Proxy.
294 */
295 proxy?: boolean | AuroraProxyProps;
296 }
297
298 export interface AuroraDatabase {
299 secret: SecretResource;
300 subnetGroup: DBSubnetGroupResource;
301 clusterParameterGroup?: DBClusterParameterGroupResource;
302 parameterGroup?: DBParameterGroupResource;
303 cluster: DBClusterResource;
304 writer: DBInstanceResource;
305 readers: DBInstanceResource[];
306 instances: [DBInstanceResource, ...DBInstanceResource[]];
307 proxy?: {
308 role: IAM.Role;
309 proxy: DBProxyResource;
310 targetGroup: DBProxyTargetGroupResource;
311 endpoint?: DBProxyEndpointResource;
312 };
313 }
314
315 const mergeTags = (
316 base: AuroraProps["tags"] | undefined,
317 extra: Record<string, Input<string>> | undefined,
318 ) => ({
319 ...base,
320 ...extra,
321 });
322
323 const inferProxyEngineFamily = (engine: string) => {
324 if (engine.includes("postgres")) {
325 return "POSTGRESQL" as const;
326 }
327 if (engine.includes("mysql")) {
328 return "MYSQL" as const;
329 }
330 return "POSTGRESQL" as const;
331 };
332
333 /**
334 * Opinionated Aurora bring-up helper.
335 *
336 * `Aurora` is the fast-start L2 for getting a working database online with one
337 * call. It creates a generated admin secret, DB subnet group, Aurora cluster,
338 * and a single writer instance by default. Optional readers, parameter groups,
339 * and an auto-wired RDS Proxy can be enabled as needs grow.
340 *
341 * The return value intentionally exposes the underlying `DB*` resources so
342 * users can expand into the lower-level surface without rewriting the stack.
343 * ### Creating a Database
344 * **Example:** Start a Small Aurora Cluster
345 * ```typescript
346 * const db = yield* AWS.RDS.Aurora("AppDb", {
347 * subnetIds: [privateSubnetA.subnetId, privateSubnetB.subnetId],
348 * securityGroupIds: [databaseSecurityGroup.groupId],
349 * });
350 * ```
351 *
352 * ### Scaling Out
353 * **Example:** Add Readers and a Proxy
354 * ```typescript
355 * const db = yield* AWS.RDS.Aurora("AppDb", {
356 * subnetIds: [privateSubnetA.subnetId, privateSubnetB.subnetId],
357 * securityGroupIds: [databaseSecurityGroup.groupId],
358 * readers: 2,
359 * proxy: true,
360 * });
361 * ```
362 *
363 * ### Migrations
364 * **Example:** Apply migrations once the writer is up
365 * ```typescript
366 * const db = yield* AWS.RDS.Aurora("AppDb", {
367 * subnetIds: [privateSubnetA.subnetId, privateSubnetB.subnetId],
368 * securityGroupIds: [databaseSecurityGroup.groupId],
369 * migrations: "./migrations",
370 * });
371 * ```
372 *
373 * **Example:** Apply migrations through an in-VPC runner without the Data API
374 * ```typescript
375 * const runner = yield* AWS.RDS.MigrationRunner("MigrationRunner", {
376 * subnetIds: [privateSubnetA.subnetId, privateSubnetB.subnetId],
377 * securityGroupIds: [runnerSecurityGroup.groupId],
378 * });
379 * const db = yield* AWS.RDS.Aurora("AppDb", {
380 * subnetIds: [privateSubnetA.subnetId, privateSubnetB.subnetId],
381 * securityGroupIds: [databaseSecurityGroup.groupId],
382 * dataApi: false,
383 * migrations: "./migrations",
384 * migrationsTransport: runner,
385 * });
386 * ```
387 *
388 * ### Querying from a Function
389 * **Example:** Query over the Data API
390 * ```typescript
391 * // the Data API is enabled by default (dataApi: true) — bind
392 * // AWS.RDSData.ExecuteStatement to query without a VPC socket
393 * const executeStatement = yield* AWS.RDSData.ExecuteStatement(db.cluster, {
394 * secret: db.secret,
395 * database: "app",
396 * });
397 * const result = yield* executeStatement({ sql: "SELECT 1" });
398 * ```
399 *
400 * @resource
401 */
402 export const Aurora = (id: string, props: AuroraProps) =>
403 Namespace.push(
404 id,
405 Effect.gen(function* () {
406 const engine = props.engine ?? "aurora-postgresql";
407 if (props.migrationsTransport === "data-api" && props.dataApi === false) {
408 return yield* Effect.die(
409 new MigrationError({
410 message: `Aurora '${id}': migrationsTransport "data-api" requires "dataApi" to be enabled.`,
411 }),
412 );
413 }
414 if (props.migrations && engine !== "aurora-postgresql" && engine !== "aurora-mysql") {
415 return yield* Effect.die(
416 new MigrationError({
417 message: `Aurora '${id}': "migrations" support the "aurora-postgresql" and "aurora-mysql" engines (got "${engine}").`,
418 }),
419 );
420 }
421 const engineVersion = props.engineVersion;
422 const databaseName = props.databaseName ?? "app";
423 const username = props.secret?.username ?? "app";
424 const subnetIds = props.subnetIds;
425 const securityGroupIds = props.securityGroupIds;
426 const commonTags = props.tags;
427 const proxyConfig: AuroraProxyProps | undefined =
428 props.proxy === true ? {} : props.proxy || undefined;
429
430 const secret =
431 props.secret?.resource ??
432 (yield* Secret("Secret", {
433 name: props.secret?.name,
434 description: props.secret?.description ?? `Credentials for Aurora database ${id}`,
435 kmsKeyId: props.secret?.kmsKeyId,
436 secretString: props.secret?.secretString,
437 secretBinary: props.secret?.secretBinary,
438 generateSecretString:
439 props.secret?.secretString || props.secret?.secretBinary
440 ? undefined
441 : {
442 secretStringTemplate: JSON.stringify({ username }),
443 generateStringKey: "password",
444 PasswordLength: 32,
445 ExcludeCharacters: "\"'@/\\",
446 ...props.secret?.generateSecretString,
447 },
448 tags: mergeTags(commonTags, props.secret?.tags),
449 }));
450
451 const subnetGroup = yield* DBSubnetGroup("SubnetGroup", {
452 dbSubnetGroupName: props.subnetGroup?.dbSubnetGroupName,
453 description: props.subnetGroup?.description,
454 subnetIds,
455 tags: mergeTags(commonTags, props.subnetGroup?.tags),
456 });
457
458 const clusterParameterGroup = props.clusterParameterGroup
459 ? yield* DBClusterParameterGroup("ClusterParameterGroup", {
460 dbClusterParameterGroupName: props.clusterParameterGroup.dbClusterParameterGroupName,
461 family: props.clusterParameterGroup.family,
462 description: props.clusterParameterGroup.description,
463 tags: mergeTags(commonTags, props.clusterParameterGroup.tags),
464 })
465 : undefined;
466
467 const parameterGroup = props.parameterGroup
468 ? yield* DBParameterGroup("ParameterGroup", {
469 dbParameterGroupName: props.parameterGroup.dbParameterGroupName,
470 family: props.parameterGroup.family,
471 description: props.parameterGroup.description,
472 tags: mergeTags(commonTags, props.parameterGroup.tags),
473 })
474 : undefined;
475
476 // Enhanced-monitoring role: reuse an explicit ARN, otherwise auto-create
477 // one when a non-zero interval is requested.
478 const monitoringInterval = props.monitoring?.interval;
479 const monitoringRole =
480 monitoringInterval !== undefined &&
481 (toWireSeconds(monitoringInterval) ?? 0) > 0 &&
482 !props.monitoring?.roleArn
483 ? yield* IAM.Role("MonitoringRole", {
484 assumeRolePolicyDocument: {
485 Version: "2012-10-17",
486 Statement: [
487 {
488 Effect: "Allow",
489 Principal: { Service: "monitoring.rds.amazonaws.com" },
490 Action: ["sts:AssumeRole"],
491 Resource: ["*"],
492 },
493 ],
494 },
495 managedPolicyArns: [
496 "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole",
497 ],
498 tags: mergeTags(commonTags, undefined),
499 })
500 : undefined;
501 const monitoringRoleArn = props.monitoring?.roleArn ?? monitoringRole?.roleArn; // prettier-ignore
502
503 const cluster = yield* DBCluster("Cluster", {
504 engine,
505 engineVersion,
506 databaseName,
507 dbSubnetGroupName: subnetGroup.dbSubnetGroupName,
508 dbClusterParameterGroupName: clusterParameterGroup?.dbClusterParameterGroupName,
509 vpcSecurityGroupIds: securityGroupIds,
510 enableHttpEndpoint: props.dataApi ?? true,
511 copyTagsToSnapshot: props.cluster?.copyTagsToSnapshot ?? true,
512 deletionProtection: props.cluster?.deletionProtection ?? props.deletionProtection ?? false,
513 backupRetentionPeriod: props.cluster?.backupRetentionPeriod ?? props.backupRetentionPeriod,
514 preferredBackupWindow: props.cluster?.preferredBackupWindow ?? props.preferredBackupWindow,
515 preferredMaintenanceWindow:
516 props.cluster?.preferredMaintenanceWindow ?? props.preferredMaintenanceWindow,
517 storageEncrypted: props.cluster?.storageEncrypted ?? props.storageEncrypted,
518 kmsKeyId: props.cluster?.kmsKeyId ?? props.kmsKeyId,
519 enableIAMDatabaseAuthentication:
520 props.cluster?.enableIAMDatabaseAuthentication ?? props.enableIAMDatabaseAuthentication,
521 enableCloudwatchLogsExports:
522 props.cluster?.enableCloudwatchLogsExports ?? props.enableCloudwatchLogsExports,
523 caCertificateIdentifier:
524 props.cluster?.caCertificateIdentifier ?? props.caCertificateIdentifier,
525 port: props.cluster?.port ?? props.port,
526 backtrackWindow: props.cluster?.backtrackWindow ?? props.backtrackWindow,
527 monitoringInterval: props.cluster?.monitoringInterval ?? monitoringInterval,
528 monitoringRoleArn: props.cluster?.monitoringRoleArn ?? monitoringRoleArn,
529 enablePerformanceInsights:
530 props.cluster?.enablePerformanceInsights ?? props.monitoring?.performanceInsights,
531 serverlessV2ScalingConfiguration:
532 props.cluster?.serverlessV2ScalingConfiguration ??
533 (props.scaling
534 ? {
535 MinCapacity: props.scaling.minCapacity ?? 0.5,
536 MaxCapacity: props.scaling.maxCapacity ?? 1,
537 }
538 : {
539 MinCapacity: 0.5,
540 MaxCapacity: 1,
541 }),
542 masterUserSecretArn: secret.secretArn,
543 tags: mergeTags(commonTags, props.cluster?.tags),
544 ...props.cluster,
545 });
546
547 const defaultInstanceClass =
548 props.instance?.dbInstanceClass ?? props.instanceClass ?? "db.serverless";
549
550 const writer = yield* DBInstance("Writer", {
551 dbClusterIdentifier: cluster.dbClusterIdentifier,
552 dbInstanceClass: defaultInstanceClass,
553 engine,
554 engineVersion,
555 dbSubnetGroupName: subnetGroup.dbSubnetGroupName,
556 dbParameterGroupName: parameterGroup?.dbParameterGroupName,
557 // No vpcSecurityGroupIds: cluster members inherit security groups from
558 // the DB cluster. Passing them here fails with "The requested DB
559 // Instance will be a member of a DB Cluster. Set vpc security group
560 // for the DB Cluster."
561 publiclyAccessible: props.instance?.publiclyAccessible ?? false,
562 promotionTier: props.instance?.promotionTier ?? 0,
563 autoMinorVersionUpgrade: props.instance?.autoMinorVersionUpgrade ?? true,
564 copyTagsToSnapshot: props.instance?.copyTagsToSnapshot ?? true,
565 monitoringInterval: props.instance?.monitoringInterval ?? monitoringInterval, // prettier-ignore
566 monitoringRoleArn: props.instance?.monitoringRoleArn ?? monitoringRoleArn,
567 enablePerformanceInsights:
568 props.instance?.enablePerformanceInsights ?? props.monitoring?.performanceInsights,
569 tags: mergeTags(commonTags, props.instance?.tags),
570 ...props.instance,
571 migrations: props.migrations,
572 migrationsTransport: props.migrationsTransport,
573 migrationsSecretArn: props.migrations ? secret.secretArn : undefined,
574 });
575
576 const readers = yield* Effect.all(
577 Array.from({ length: props.readers ?? 0 }, (_, index) =>
578 DBInstance(`Reader${index + 1}`, {
579 dbClusterIdentifier: cluster.dbClusterIdentifier,
580 dbInstanceClass: defaultInstanceClass,
581 engine,
582 engineVersion,
583 dbSubnetGroupName: subnetGroup.dbSubnetGroupName,
584 dbParameterGroupName: parameterGroup?.dbParameterGroupName,
585 // No vpcSecurityGroupIds: security groups belong on the DB
586 // cluster, not its member instances (see Writer above).
587 publiclyAccessible: props.instance?.publiclyAccessible ?? false,
588 promotionTier: index + 1,
589 autoMinorVersionUpgrade: props.instance?.autoMinorVersionUpgrade ?? true,
590 copyTagsToSnapshot: props.instance?.copyTagsToSnapshot ?? true,
591 monitoringInterval: props.instance?.monitoringInterval ?? monitoringInterval, // prettier-ignore
592 monitoringRoleArn: props.instance?.monitoringRoleArn ?? monitoringRoleArn,
593 enablePerformanceInsights:
594 props.instance?.enablePerformanceInsights ?? props.monitoring?.performanceInsights,
595 tags: mergeTags(commonTags, props.instance?.tags),
596 ...props.instance,
597 }),
598 ),
599 { concurrency: "unbounded" },
600 );
601
602 const createProxy = Effect.gen(function* () {
603 if (proxyConfig === undefined) {
604 return undefined;
605 }
606
607 const role = yield* IAM.Role("ProxyRole", {
608 assumeRolePolicyDocument: {
609 Version: "2012-10-17",
610 Statement: [
611 {
612 Effect: "Allow",
613 Principal: {
614 Service: "rds.amazonaws.com",
615 },
616 Action: ["sts:AssumeRole"],
617 Resource: ["*"],
618 },
619 ],
620 },
621 inlinePolicies: {
622 ReadSecret: {
623 Version: "2012-10-17",
624 Statement: [
625 {
626 Effect: "Allow",
627 Action: ["secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret"],
628 Resource: [secret.secretArn],
629 },
630 ],
631 },
632 },
633 tags: mergeTags(commonTags, undefined),
634 });
635
636 const proxy = yield* DBProxy("Proxy", {
637 dbProxyName: proxyConfig.dbProxyName,
638 engineFamily: inferProxyEngineFamily(engine),
639 auth: proxyConfig.auth ?? [
640 {
641 AuthScheme: "SECRETS",
642 SecretArn: secret.secretArn,
643 IAMAuth: "DISABLED",
644 },
645 ],
646 roleArn: role.roleArn,
647 vpcSubnetIds: subnetIds,
648 vpcSecurityGroupIds: securityGroupIds,
649 requireTLS: proxyConfig.requireTLS ?? true,
650 idleClientTimeout: proxyConfig.idleClientTimeout,
651 debugLogging: proxyConfig.debugLogging,
652 endpointNetworkType: proxyConfig.endpointNetworkType,
653 targetConnectionNetworkType: proxyConfig.targetConnectionNetworkType,
654 tags: mergeTags(commonTags, proxyConfig.tags),
655 });
656
657 const targetGroup = yield* DBProxyTargetGroup("ProxyTargetGroup", {
658 targetGroupName: proxyConfig.targetGroup?.targetGroupName,
659 dbProxyName: proxy.dbProxyName,
660 dbClusterIdentifiers: [cluster.dbClusterIdentifier],
661 dbInstanceIdentifiers: proxyConfig.targetGroup?.dbInstanceIdentifiers,
662 connectionPoolConfig: proxyConfig.targetGroup?.connectionPoolConfig,
663 });
664
665 const endpoint =
666 proxyConfig.endpoint === undefined
667 ? undefined
668 : yield* DBProxyEndpoint("ProxyEndpoint", {
669 dbProxyName: proxy.dbProxyName,
670 vpcSubnetIds: subnetIds,
671 vpcSecurityGroupIds: securityGroupIds,
672 ...(proxyConfig.endpoint === true ? {} : proxyConfig.endpoint),
673 tags: mergeTags(
674 commonTags,
675 proxyConfig.endpoint === true ? undefined : proxyConfig.endpoint.tags,
676 ),
677 });
678
679 return {
680 role,
681 proxy,
682 targetGroup,
683 endpoint,
684 };
685 });
686 const proxy = yield* createProxy;
687
688 return {
689 secret,
690 subnetGroup,
691 clusterParameterGroup,
692 parameterGroup,
693 cluster,
694 writer,
695 readers,
696 instances: [writer, ...readers] as [DBInstanceResource, ...DBInstanceResource[]],
697 proxy,
698 } satisfies AuroraDatabase as AuroraDatabase;
699 }),
700 );