@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, 07:15 UTC

main
ts 76 lines 2.71 KB
Raw
1 import { Network } from "@alchemy.run/aws/EC2/Network";
2 import { SecurityGroup } from "@alchemy.run/aws/EC2/SecurityGroup";
3 import * as RDS from "@alchemy.run/aws/RDS";
4 import * as Effect from "effect/Effect";
5
6 /**
7 * A standalone Postgres `DBInstance` for the `RDS.Connect` fixture, shared by
8 * the Lambda fixture and the test's stack program (declarations dedupe by
9 * logical ID).
10 *
11 * Topology: an isolated network (no NAT), a security group for the
12 * VPC-attached Lambda, a database security group that admits Postgres from
13 * that Lambda only, and an endpoint security group that admits HTTPS from it
14 * (the test adds a Secrets Manager interface endpoint so the Lambda can read
15 * the instance's managed master secret).
16 */
17 export const RdsConnectInfra = Effect.gen(function* () {
18 const network = yield* Network("ConnectNet", { cidrBlock: "10.48.0.0/16" });
19
20 const lambdaSecurityGroup = yield* SecurityGroup("ConnectLambdaSecurityGroup", {
21 vpcId: network.vpcId,
22 description: "VPC-attached Lambda for the RDS.Connect DBInstance fixture",
23 });
24
25 const dbSecurityGroup = yield* SecurityGroup("ConnectDbSecurityGroup", {
26 vpcId: network.vpcId,
27 description: "RDS.Connect DBInstance (Postgres from the Lambda SG)",
28 ingress: [
29 {
30 ipProtocol: "tcp",
31 fromPort: 5432,
32 toPort: 5432,
33 referencedGroupId: lambdaSecurityGroup.groupId,
34 description: "Postgres from the RDS.Connect Lambda",
35 },
36 ],
37 });
38
39 const endpointSecurityGroup = yield* SecurityGroup("ConnectEndpointSecurityGroup", {
40 vpcId: network.vpcId,
41 description: "Secrets Manager endpoint (HTTPS from the Lambda SG)",
42 ingress: [
43 {
44 ipProtocol: "tcp",
45 fromPort: 443,
46 toPort: 443,
47 referencedGroupId: lambdaSecurityGroup.groupId,
48 description: "HTTPS from the RDS.Connect Lambda",
49 },
50 ],
51 });
52
53 const subnetGroup = yield* RDS.DBSubnetGroup("ConnectSubnetGroup", {
54 description: "RDS.Connect DBInstance fixture",
55 subnetIds: network.privateSubnetIds,
56 });
57
58 // No `Secret` resource: the instance's credentials live in the
59 // RDS-managed master user secret, which `RDS.Connect` reads by default.
60 const instance = yield* RDS.DBInstance("ConnectInstance", {
61 engine: "postgres",
62 dbInstanceClass: "db.t3.micro",
63 allocatedStorage: 20,
64 storageType: "gp2",
65 masterUsername: "alchemy",
66 manageMasterUserPassword: true,
67 enableIAMDatabaseAuthentication: true,
68 backupRetentionPeriod: "1 day",
69 deletionProtection: false,
70 dbSubnetGroupName: subnetGroup.dbSubnetGroupName,
71 vpcSecurityGroupIds: [dbSecurityGroup.groupId],
72 publiclyAccessible: false,
73 });
74
75 return { network, lambdaSecurityGroup, endpointSecurityGroup, instance };
76 });