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.getProjectsLocationsPrivateClouds({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("2 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32test.provider(
33 "getProjectsLocationsPrivateClouds on a missing private cloud fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 vmwareengine.getProjectsLocationsPrivateClouds({
42 name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-pc-missing`,
43 }),
44 );
45 expect(error._tag).toEqual("NotFound");
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
51 timeout: 90_000,
52 },
53);
54
55test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete a private cloud",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
64 type: "STANDARD",
65 description: "cloud parent",
66 });
67 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
68 location: "us-central1-a",
69 type: "STANDARD",
70 networkConfig: {
71 managementCidr: "192.168.1.0/24",
72 vmwareEngineNetwork: ven.name,
73 },
74 managementCluster: {
75 clusterId: "mgmt",
76 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
77 },
78 description: "alchemy-test-pc",
79 });
80 return { ven, cloud };
81 }),
82 );
83
84 expect(created.cloud.name).toContain("/privateClouds/");
85 expect(created.cloud.location).toEqual("us-central1-a");
86 expect(created.cloud.description).toEqual("alchemy-test-pc");
87
88 const fetched = yield* vmwareengine.getProjectsLocationsPrivateClouds({
89 name: created.cloud.name,
90 });
91 expect(fetched.name).toEqual(created.cloud.name);
92 expect(fetched.description).toContain("alchemy-id=");
93 expect(fetched.description).toContain("alchemy-test-pc");
94
95 const updated = yield* stack.deploy(
96 Effect.gen(function* () {
97 const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
98 vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId,
99 type: "STANDARD",
100 description: "cloud parent",
101 });
102 const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", {
103 privateCloudId: created.cloud.privateCloudId,
104 location: "us-central1-a",
105 type: "STANDARD",
106 networkConfig: {
107 managementCidr: "192.168.1.0/24",
108 vmwareEngineNetwork: ven.name,
109 },
110 managementCluster: {
111 clusterId: "mgmt",
112 nodeTypeConfigs: { "standard-72": { nodeCount: 3 } },
113 },
114 description: "alchemy-prod-pc",
115 });
116 return { ven, cloud };
117 }),
118 );
119
120 expect(updated.cloud.name).toEqual(created.cloud.name);
121 expect(updated.cloud.description).toEqual("alchemy-prod-pc");
122
123 yield* stack.destroy();
124
125 const gone = yield* waitUntilGone(created.cloud.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 {
129 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
130 timeout: 120_000,
131 },
132);