1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as vmwareengine from "@distilled.cloud/gcp/vmwareengine_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import * as Schedule from "effect/Schedule";
8import { GcpEnvironment } from "@/GCP/Environment";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17// Private clouds need VMware Engine node quota and bill thousands of dollars
18// a month; set GCP_TEST_VMWAREENGINE=1 on an entitled project to opt in.
19const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST;
20
21const waitUntilGone = (name: string) =>
22 vmwareengine
23 .getProjectsLocationsPrivateCloudsExternalAddresses({ name })
24 .pipe(
25 Effect.as("found" as const),
26 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
27 Effect.repeat({
28 schedule: Schedule.spaced("2 seconds"),
29 until: (status) => status === "gone",
30 times: 10,
31 }),
32 );
33
34test.provider(
35 "getProjectsLocationsPrivateCloudsExternalAddresses on a missing address fails with a typed tag",
36 (stack) =>
37 Effect.gen(function* () {
38 const { project } = yield* GcpEnvironment.current;
39
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 vmwareengine.getProjectsLocationsPrivateCloudsExternalAddresses({
44 name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-missing/externalAddresses/missing`,
45 }),
46 );
47 expect(error._tag).toEqual("NotFound");
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 {
52 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
53 timeout: 90_000,
54 },
55);
56
57test.provider.skipIf(!runLifecycle)(
58 "create, update, and delete an external address",
59 (stack) =>
60 Effect.gen(function* () {
61 yield* stack.destroy();
62
63 const created = yield* stack.deploy(
64 Effect.gen(function* () {
65 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
66 type: "STANDARD",
67 description: "address grandparent",
68 });
69 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
70 location: "us-central1-a",
71 networkConfig: {
72 managementCidr: "192.168.1.0/24",
73 vmwareEngineNetwork: ven.name,
74 },
75 managementCluster: {
76 clusterId: "mgmt",
77 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
78 },
79 description: "address parent",
80 });
81 const address = yield* GCP.VMwareEngine.PrivateCloudsExternalAddress(
82 "Web",
83 {
84 privateCloud: cloud.name,
85 internalIp: "192.168.1.10",
86 description: "alchemy-test-ea",
87 },
88 );
89 return { ven, cloud, address };
90 }),
91 );
92
93 expect(created.address.name).toContain("/externalAddresses/");
94 expect(created.address.internalIp).toEqual("192.168.1.10");
95 expect(created.address.description).toEqual("alchemy-test-ea");
96
97 const fetched =
98 yield* vmwareengine.getProjectsLocationsPrivateCloudsExternalAddresses({
99 name: created.address.name,
100 });
101 expect(fetched.name).toEqual(created.address.name);
102 expect(fetched.description).toContain("alchemy-id=");
103 expect(fetched.description).toContain("alchemy-test-ea");
104
105 const updated = yield* stack.deploy(
106 Effect.gen(function* () {
107 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
108 vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId,
109 type: "STANDARD",
110 description: "address grandparent",
111 });
112 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
113 privateCloudId: created.cloud.privateCloudId,
114 location: "us-central1-a",
115 networkConfig: {
116 managementCidr: "192.168.1.0/24",
117 vmwareEngineNetwork: ven.name,
118 },
119 managementCluster: {
120 clusterId: "mgmt",
121 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
122 },
123 description: "address parent",
124 });
125 const address = yield* GCP.VMwareEngine.PrivateCloudsExternalAddress(
126 "Web",
127 {
128 privateCloud: cloud.name,
129 externalAddressId: created.address.externalAddressId,
130 internalIp: "192.168.1.11",
131 description: "alchemy-prod-ea",
132 },
133 );
134 return { ven, cloud, address };
135 }),
136 );
137
138 expect(updated.address.name).toEqual(created.address.name);
139 expect(updated.address.internalIp).toEqual("192.168.1.11");
140 expect(updated.address.description).toEqual("alchemy-prod-ea");
141
142 yield* stack.destroy();
143
144 const gone = yield* waitUntilGone(created.address.name);
145 expect(gone).toEqual("gone");
146 }).pipe(logLevel),
147 {
148 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
149 timeout: 120_000,
150 },
151);