1import * as AWS from "@/AWS";
2import { RouteTable, Vpc, VpcEndpoint } from "@/AWS/EC2";
3import { AWSEnvironment } from "@/AWS/Environment";
4import * as Provider from "@/Provider";
5import * as Test from "./VpcTest.ts";
6import { expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8import { MinimumLogLevel } from "effect/References";
9import { assertVpcGone } from "./Gone.ts";
10
11const { test } = Test.make({ providers: AWS.providers() });
12
13const logLevel = Effect.provideService(
14 MinimumLogLevel,
15 process.env.DEBUG ? "Debug" : "Info",
16);
17
18test.provider(
19 "list enumerates the deployed VpcEndpoint",
20 (stack) =>
21 Effect.gen(function* () {
22 const { region } = yield* AWSEnvironment.current;
23
24 yield* stack.destroy();
25
26 const deployed = yield* stack.deploy(
27 Effect.gen(function* () {
28 const vpc = yield* Vpc("ListVpceVpc", {
29 cidrBlock: "10.0.0.0/16",
30 });
31 const routeTable = yield* RouteTable("ListVpceRouteTable", {
32 vpcId: vpc.vpcId,
33 });
34 const endpoint = yield* VpcEndpoint("ListVpceEndpoint", {
35 vpcId: vpc.vpcId,
36 serviceName: `com.amazonaws.${region}.s3`,
37 vpcEndpointType: "Gateway",
38 routeTableIds: [routeTable.routeTableId],
39 });
40 return { vpc, endpoint };
41 }),
42 );
43
44 const provider = yield* Provider.findProvider(VpcEndpoint);
45 const all = yield* provider.list();
46
47 expect(
48 all.some((x) => x.vpcEndpointId === deployed.endpoint.vpcEndpointId),
49 ).toBe(true);
50
51 yield* stack.destroy();
52
53 // The VPC cannot delete while the endpoint or route table exist —
54 // VPC-gone proves full teardown.
55 yield* assertVpcGone(deployed.vpc.vpcId);
56 }).pipe(logLevel),
57 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
58);