1import * as AWS from "@/AWS";
2import { NetworkAcl, NetworkAclAssociation, Subnet } from "@/AWS/EC2";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import { expect } from "alchemy-test";
6import * as Data from "effect/Data";
7import * as Effect from "effect/Effect";
8import { MinimumLogLevel } from "effect/References";
9import * as Schedule from "effect/Schedule";
10import { getDefaultVpc } from "../DefaultVpc.ts";
11import { assertNetworkAclGone, assertSubnetGone } from "./Gone.ts";
12
13const { test } = Test.make({ providers: AWS.providers() });
14
15const logLevel = Effect.provideService(
16 MinimumLogLevel,
17 process.env.DEBUG ? "Debug" : "Info",
18);
19
20class NetworkAclAssociationNotListed extends Data.TaggedError(
21 "NetworkAclAssociationNotListed",
22)<{}> {}
23
24test.provider(
25 "list enumerates the deployed NetworkAclAssociation",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const defaultVpc = yield* getDefaultVpc;
31 const { subnet, acl, assoc } = yield* stack.deploy(
32 Effect.gen(function* () {
33 const subnet = yield* Subnet("ListNaclAssocSubnet", {
34 vpcId: defaultVpc.vpcId,
35 cidrBlock: defaultVpc.subnetCidrBlock(221),
36 });
37 const acl = yield* NetworkAcl("ListNaclAssocAcl", {
38 vpcId: defaultVpc.vpcId,
39 });
40 const assoc = yield* NetworkAclAssociation("ListNaclAssoc", {
41 networkAclId: acl.networkAclId,
42 subnetId: subnet.subnetId,
43 });
44 return { subnet, acl, assoc };
45 }),
46 );
47
48 const provider = yield* Provider.findProvider(NetworkAclAssociation);
49 const all = yield* provider.list().pipe(
50 Effect.flatMap((all) =>
51 all.some((x) => x.associationId === assoc.associationId)
52 ? Effect.succeed(all)
53 : Effect.fail(new NetworkAclAssociationNotListed()),
54 ),
55 Effect.retry({
56 while: (e) => e._tag === "NetworkAclAssociationNotListed",
57 schedule: Schedule.max([
58 Schedule.spaced("3 seconds"),
59 Schedule.recurs(10),
60 ]),
61 }),
62 );
63
64 expect(all.some((x) => x.associationId === assoc.associationId)).toBe(
65 true,
66 );
67
68 yield* stack.destroy();
69
70 // The default VPC is shared/standing — assert the resources this test
71 // created inside it (subnet + ACL, whose deletion also proves the
72 // association was released) are gone.
73 yield* assertNetworkAclGone(acl.networkAclId);
74 yield* assertSubnetGone(subnet.subnetId);
75 }).pipe(logLevel),
76 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
77);