| 1 | import * as AWS from "@/AWS"; |
| 2 | import { NetworkAcl, NetworkAclEntry, Vpc } from "@/AWS/EC2"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "./VpcTest.ts"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import { assertVpcGone } from "./Gone.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | test.provider( |
| 18 | "list enumerates the deployed Network ACL Entry", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const { vpc, entry } = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | const vpc = yield* Vpc("ListNaclEntryVpc", { |
| 26 | cidrBlock: "10.0.0.0/16", |
| 27 | }); |
| 28 | const acl = yield* NetworkAcl("ListNaclEntryAcl", { |
| 29 | vpcId: vpc.vpcId, |
| 30 | }); |
| 31 | const entry = yield* NetworkAclEntry("ListNaclEntry", { |
| 32 | networkAclId: acl.networkAclId, |
| 33 | ruleNumber: 100, |
| 34 | protocol: "6", |
| 35 | ruleAction: "allow", |
| 36 | egress: false, |
| 37 | cidrBlock: "0.0.0.0/0", |
| 38 | portRange: { from: 443, to: 443 }, |
| 39 | }); |
| 40 | return { vpc, acl, entry }; |
| 41 | }), |
| 42 | ); |
| 43 | |
| 44 | const provider = yield* Provider.findProvider(NetworkAclEntry); |
| 45 | const all = yield* provider.list(); |
| 46 | |
| 47 | expect( |
| 48 | all.some( |
| 49 | (x) => |
| 50 | x.networkAclId === entry.networkAclId && |
| 51 | x.ruleNumber === entry.ruleNumber && |
| 52 | x.egress === entry.egress, |
| 53 | ), |
| 54 | ).toBe(true); |
| 55 | |
| 56 | yield* stack.destroy(); |
| 57 | |
| 58 | // The VPC cannot delete while the ACL (and its entries) exists — VPC-gone |
| 59 | // proves full teardown. |
| 60 | yield* assertVpcGone(vpc.vpcId); |
| 61 | }).pipe(logLevel), |
| 62 | { tags: ["provider:aws", "provider:aws:ec2", "live"] }, |
| 63 | ); |