| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as vmwareengine from "@distilled.cloud/gcp/vmwareengine_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const 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. |
| 19 | const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | vmwareengine.getProjectsLocationsPrivateCloudsClusters({ 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 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsPrivateCloudsClusters on a missing cluster 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.getProjectsLocationsPrivateCloudsClusters({ |
| 42 | name: `projects/${project}/locations/us-central1-a/privateClouds/alchemy-missing/clusters/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 | |
| 55 | test.provider.skipIf(!runLifecycle)( |
| 56 | "create, update, and delete a private cloud cluster", |
| 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: "cluster grandparent", |
| 66 | }); |
| 67 | const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", { |
| 68 | location: "us-central1-a", |
| 69 | networkConfig: { |
| 70 | managementCidr: "192.168.1.0/24", |
| 71 | vmwareEngineNetwork: ven.name, |
| 72 | }, |
| 73 | managementCluster: { |
| 74 | clusterId: "mgmt", |
| 75 | nodeTypeConfigs: { "standard-72": { nodeCount: 3 } }, |
| 76 | }, |
| 77 | description: "cluster parent", |
| 78 | }); |
| 79 | const cluster = yield* GCP.VMwareEngine.PrivateCloudsCluster("Work", { |
| 80 | privateCloud: cloud.name, |
| 81 | nodeTypeConfigs: { "standard-72": { nodeCount: 3 } }, |
| 82 | }); |
| 83 | return { ven, cloud, cluster }; |
| 84 | }), |
| 85 | ); |
| 86 | |
| 87 | expect(created.cluster.name).toContain("/clusters/"); |
| 88 | expect(created.cluster.management).toEqual(false); |
| 89 | expect(created.cluster.privateCloud).toEqual(created.cloud.name); |
| 90 | |
| 91 | const fetched = |
| 92 | yield* vmwareengine.getProjectsLocationsPrivateCloudsClusters({ |
| 93 | name: created.cluster.name, |
| 94 | }); |
| 95 | expect(fetched.name).toEqual(created.cluster.name); |
| 96 | expect(fetched.management).toEqual(false); |
| 97 | |
| 98 | const updated = yield* stack.deploy( |
| 99 | Effect.gen(function* () { |
| 100 | const ven = yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", { |
| 101 | vmwareEngineNetworkId: created.ven.vmwareEngineNetworkId, |
| 102 | type: "STANDARD", |
| 103 | description: "cluster grandparent", |
| 104 | }); |
| 105 | const cloud = yield* GCP.VMwareEngine.PrivateCloud("Sddc", { |
| 106 | privateCloudId: created.cloud.privateCloudId, |
| 107 | location: "us-central1-a", |
| 108 | networkConfig: { |
| 109 | managementCidr: "192.168.1.0/24", |
| 110 | vmwareEngineNetwork: ven.name, |
| 111 | }, |
| 112 | managementCluster: { |
| 113 | clusterId: "mgmt", |
| 114 | nodeTypeConfigs: { "standard-72": { nodeCount: 3 } }, |
| 115 | }, |
| 116 | description: "cluster parent", |
| 117 | }); |
| 118 | const cluster = yield* GCP.VMwareEngine.PrivateCloudsCluster("Work", { |
| 119 | privateCloud: cloud.name, |
| 120 | clusterId: created.cluster.clusterId, |
| 121 | nodeTypeConfigs: { "standard-72": { nodeCount: 4 } }, |
| 122 | }); |
| 123 | return { ven, cloud, cluster }; |
| 124 | }), |
| 125 | ); |
| 126 | |
| 127 | expect(updated.cluster.name).toEqual(created.cluster.name); |
| 128 | expect( |
| 129 | updated.cluster.nodeTypeConfigs?.["standard-72"]?.nodeCount, |
| 130 | ).toEqual(4); |
| 131 | |
| 132 | yield* stack.destroy(); |
| 133 | |
| 134 | const gone = yield* waitUntilGone(created.cluster.name); |
| 135 | expect(gone).toEqual("gone"); |
| 136 | }).pipe(logLevel), |
| 137 | { |
| 138 | tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"], |
| 139 | timeout: 120_000, |
| 140 | }, |
| 141 | ); |