1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as compute from "@distilled.cloud/gcp/compute_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
17const runLifecycle = !process.env.FAST;
18
19const waitUntilGone = (project: string, globalVmExtensionPolicy: string) =>
20 compute
21 .getGlobalVmExtensionPolicies({ project, globalVmExtensionPolicy })
22 .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.skipIf(!runLifecycle)(
33 "create, update, and delete a global VM extension policy",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 return yield* GCP.Compute.GlobalVmExtensionPolicy("Ops", {
41 description: "ops agent",
42 extensionPolicies: { "ops-agent": {} },
43 rolloutOperation: {
44 rolloutInput: { predefinedRolloutPlan: "FAST_ROLLOUT" },
45 },
46 priority: 10,
47 });
48 }),
49 );
50
51 expect(created.policyName).toEqual(expect.any(String));
52 expect(created.description).toEqual("ops agent");
53 expect(created.priority).toEqual(10);
54
55 const fetched = yield* compute.getGlobalVmExtensionPolicies({
56 project: created.project,
57 globalVmExtensionPolicy: created.policyName,
58 });
59 expect(fetched.name).toEqual(created.policyName);
60 expect(fetched.description).toContain("[alchemy ");
61
62 const updated = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.Compute.GlobalVmExtensionPolicy("Ops", {
65 policyName: created.policyName,
66 description: "updated ops agent",
67 extensionPolicies: { "ops-agent": {} },
68 rolloutOperation: {
69 rolloutInput: { predefinedRolloutPlan: "FAST_ROLLOUT" },
70 },
71 priority: 20,
72 });
73 }),
74 );
75 expect(updated.description).toEqual("updated ops agent");
76 expect(updated.priority).toEqual(20);
77
78 yield* stack.destroy();
79 const gone = yield* waitUntilGone(created.project, created.policyName);
80 expect(gone).toEqual("gone");
81 }).pipe(logLevel),
82 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 900_000 },
83);