The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { ClientVpnEndpoint } from "@alchemy.run/aws/EC2/ClientVpnEndpoint"; |
| 3 | import { |
| 4 | ClientVpnTargetNetworkAssociation, |
| 5 | type ClientVpnTargetNetworkAssociationProps, |
| 6 | } from "@alchemy.run/aws/EC2/ClientVpnTargetNetworkAssociation"; |
| 7 | import { describe, expect } from "@alchemy.run/test"; |
| 8 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 9 | import * as Alchemy from "alchemy"; |
| 10 | import * as Provider from "alchemy/Provider"; |
| 11 | import * as Effect from "effect/Effect"; |
| 12 | import { |
| 13 | assertClientVpnAssociationDeleted, |
| 14 | assertClientVpnCertificateDeleted, |
| 15 | clientVpnAvailabilityZones, |
| 16 | clientVpnEndpointProps, |
| 17 | clientVpnTestTimeout, |
| 18 | clientVpnNetwork, |
| 19 | importClientVpnCertificate, |
| 20 | readClientVpnTargetNetworks, |
| 21 | waitForClientVpn, |
| 22 | } from "./fixtures/client-vpn.ts"; |
| 23 | |
| 24 | describe( |
| 25 | "Client VPN target networks", |
| 26 | { tags: ["provider:aws", "provider:aws:acm", "provider:aws:ec2", "live"] }, |
| 27 | () => { |
| 28 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 29 | providers: AWS.providers(), |
| 30 | }); |
| 31 | const certificate = beforeAll(importClientVpnCertificate("ClientVpnAssociationPrerequisites")); |
| 32 | const zones = beforeAll(clientVpnAvailabilityZones); |
| 33 | const Stack = Alchemy.Stack( |
| 34 | "ClientVpnAssociationPrerequisites", |
| 35 | { providers: AWS.providers(), state: Alchemy.localState() }, |
| 36 | Effect.gen(function* () { |
| 37 | const certificateArn = yield* certificate; |
| 38 | const network = yield* clientVpnNetwork(yield* zones); |
| 39 | const endpoint = yield* ClientVpnEndpoint("Endpoint", { |
| 40 | ...clientVpnEndpointProps(certificateArn), |
| 41 | vpcId: network.vpc.vpcId, |
| 42 | splitTunnel: true, |
| 43 | }); |
| 44 | return { ...network, endpoint }; |
| 45 | }), |
| 46 | ); |
| 47 | const prerequisites = beforeAll(deploy(Stack), { timeout: clientVpnTestTimeout }); |
| 48 | afterAll( |
| 49 | destroy(Stack).pipe( |
| 50 | Effect.andThen(certificate.pipe(Effect.flatMap(assertClientVpnCertificateDeleted))), |
| 51 | ), |
| 52 | { timeout: clientVpnTestTimeout }, |
| 53 | ); |
| 54 | |
| 55 | test.provider.skipIf(!!process.env.FAST)( |
| 56 | "creates, lists, retains, replaces, and deletes target network associations", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | yield* stack.destroy(); |
| 60 | const { endpoint, vpc, firstSubnet, secondSubnet } = yield* prerequisites; |
| 61 | const clientVpnEndpointId = endpoint.clientVpnEndpointId; |
| 62 | const deployAssociation = ( |
| 63 | subnetId: ClientVpnTargetNetworkAssociationProps["subnetId"], |
| 64 | ) => |
| 65 | stack.deploy( |
| 66 | ClientVpnTargetNetworkAssociation("Association", { clientVpnEndpointId, subnetId }), |
| 67 | ); |
| 68 | const created = yield* deployAssociation(firstSubnet.subnetId); |
| 69 | expect(created.associationId).toMatch(/^cvpn-assoc-/); |
| 70 | expect(created.clientVpnEndpointId).toBe(clientVpnEndpointId); |
| 71 | expect(created.subnetId).toBe(firstSubnet.subnetId); |
| 72 | const networks = yield* waitForClientVpn( |
| 73 | readClientVpnTargetNetworks(clientVpnEndpointId), |
| 74 | (items) => |
| 75 | items.some( |
| 76 | (network) => |
| 77 | network.AssociationId === created.associationId && |
| 78 | network.Status?.Code === "associated", |
| 79 | ), |
| 80 | "associated target network", |
| 81 | ); |
| 82 | expect(networks).toContainEqual( |
| 83 | expect.objectContaining({ |
| 84 | AssociationId: created.associationId, |
| 85 | ClientVpnEndpointId: clientVpnEndpointId, |
| 86 | TargetNetworkId: firstSubnet.subnetId, |
| 87 | VpcId: vpc.vpcId, |
| 88 | }), |
| 89 | ); |
| 90 | const provider = yield* Provider.findProvider(ClientVpnTargetNetworkAssociation); |
| 91 | const listed = yield* waitForClientVpn( |
| 92 | provider.list(), |
| 93 | (items) => items.some((network) => network.associationId === created.associationId), |
| 94 | "target network provider list", |
| 95 | ); |
| 96 | expect(listed).toContainEqual( |
| 97 | expect.objectContaining({ |
| 98 | associationId: created.associationId, |
| 99 | clientVpnEndpointId, |
| 100 | subnetId: firstSubnet.subnetId, |
| 101 | }), |
| 102 | ); |
| 103 | const retained = yield* deployAssociation(firstSubnet.subnetId); |
| 104 | expect(retained.associationId).toBe(created.associationId); |
| 105 | expect( |
| 106 | (yield* readClientVpnTargetNetworks(clientVpnEndpointId)).filter( |
| 107 | (network) => |
| 108 | network.TargetNetworkId === firstSubnet.subnetId && |
| 109 | network.Status?.Code === "associated", |
| 110 | ), |
| 111 | ).toHaveLength(1); |
| 112 | |
| 113 | // Both subnet dependencies survive the replacement; they occupy different AZs. |
| 114 | const replaced = yield* deployAssociation(secondSubnet.subnetId); |
| 115 | expect(replaced.associationId).not.toBe(created.associationId); |
| 116 | expect(replaced.subnetId).toBe(secondSubnet.subnetId); |
| 117 | yield* waitForClientVpn( |
| 118 | readClientVpnTargetNetworks(clientVpnEndpointId), |
| 119 | (items) => |
| 120 | items.some( |
| 121 | (network) => |
| 122 | network.AssociationId === replaced.associationId && |
| 123 | network.TargetNetworkId === secondSubnet.subnetId && |
| 124 | network.Status?.Code === "associated", |
| 125 | ), |
| 126 | "replacement target network", |
| 127 | ); |
| 128 | yield* assertClientVpnAssociationDeleted(clientVpnEndpointId, created.associationId); |
| 129 | yield* stack.destroy(); |
| 130 | yield* assertClientVpnAssociationDeleted(clientVpnEndpointId, replaced.associationId); |
| 131 | }), |
| 132 | { timeout: clientVpnTestTimeout }, |
| 133 | ); |
| 134 | }, |
| 135 | ); |