| 1 | import { |
| 2 | InternetGateway, |
| 3 | Route, |
| 4 | RouteTable, |
| 5 | RouteTableAssociation, |
| 6 | SecurityGroup, |
| 7 | Subnet, |
| 8 | Vpc, |
| 9 | } from "@/AWS/EC2"; |
| 10 | import * as Effect from "effect/Effect"; |
| 11 | |
| 12 | /** |
| 13 | * A stack-owned public network for Batch tests. |
| 14 | * |
| 15 | * Tests must not call CreateDefaultVpc: AWS generates an untaggable collection |
| 16 | * of default subnets, routes, ACLs, security-group rules, DHCP options, and an |
| 17 | * internet gateway that no test stack owns. This graph is deterministic and |
| 18 | * lets the engine delete every component bottom-up during stack.destroy(). |
| 19 | */ |
| 20 | export const BatchTestNetwork = Effect.gen(function* () { |
| 21 | const vpc = yield* Vpc("BatchTestVpc", { |
| 22 | cidrBlock: "10.73.0.0/16", |
| 23 | }); |
| 24 | const internetGateway = yield* InternetGateway("BatchTestInternetGateway", { |
| 25 | vpcId: vpc.vpcId, |
| 26 | }); |
| 27 | const subnet = yield* Subnet("BatchTestSubnet", { |
| 28 | vpcId: vpc.vpcId, |
| 29 | cidrBlock: "10.73.1.0/24", |
| 30 | mapPublicIpOnLaunch: true, |
| 31 | // Batch creates service-managed ENIs in this subnet. Those ENIs also |
| 32 | // prevent the VPC's internet gateway from detaching, but that relationship |
| 33 | // is implicit in AWS and therefore absent from the engine's prop graph. |
| 34 | // This harmless tag records the real dependency explicitly so destroy |
| 35 | // waits for ComputeEnvironment -> Subnet before attempting IGW teardown. |
| 36 | tags: { |
| 37 | "alchemy:test:internet-gateway": internetGateway.internetGatewayId, |
| 38 | }, |
| 39 | }); |
| 40 | const securityGroup = yield* SecurityGroup("BatchTestSecurityGroup", { |
| 41 | vpcId: vpc.vpcId, |
| 42 | }); |
| 43 | const routeTable = yield* RouteTable("BatchTestRouteTable", { |
| 44 | vpcId: vpc.vpcId, |
| 45 | }); |
| 46 | yield* Route("BatchTestInternetRoute", { |
| 47 | routeTableId: routeTable.routeTableId, |
| 48 | destinationCidrBlock: "0.0.0.0/0", |
| 49 | gatewayId: internetGateway.internetGatewayId, |
| 50 | }); |
| 51 | yield* RouteTableAssociation("BatchTestSubnetRoute", { |
| 52 | routeTableId: routeTable.routeTableId, |
| 53 | subnetId: subnet.subnetId, |
| 54 | }); |
| 55 | |
| 56 | return { |
| 57 | vpcId: vpc.vpcId, |
| 58 | subnetIds: [subnet.subnetId], |
| 59 | securityGroupIds: [securityGroup.groupId], |
| 60 | }; |
| 61 | }); |