1import { GcpEnvironment } from "@/GCP/Environment";
2import type { GcpOpError } from "@distilled.cloud/gcp/vmmigration_v1";
3import { Forbidden, NotFound } from "@distilled.cloud/gcp/vmmigration_v1";
4import * as Effect from "effect/Effect";
5import { MinimumLogLevel } from "effect/References";
6import * as Schedule from "effect/Schedule";
7
8export const logLevel = Effect.provideService(
9 MinimumLogLevel,
10 process.env.DEBUG ? "Debug" : "Info",
11);
12
13// An AWS source only finishes creating once Migrate to VMs can reach AWS with
14// the credentials: with placeholder keys the create operation never completes
15// (the source stays in state PENDING). Set GCP_TEST_VMMIGRATION_AWS_ACCESS_KEY_ID
16// and GCP_TEST_VMMIGRATION_AWS_SECRET_ACCESS_KEY to run the source lifecycles.
17const awsAccessKeyId = process.env.GCP_TEST_VMMIGRATION_AWS_ACCESS_KEY_ID;
18const awsSecretAccessKey =
19 process.env.GCP_TEST_VMMIGRATION_AWS_SECRET_ACCESS_KEY;
20
21export const runSourceLifecycle = !!awsAccessKeyId && !!awsSecretAccessKey;
22
23export const currentProject = GcpEnvironment.current.pipe(
24 Effect.map((env) => env.project),
25);
26
27export const dummyAws = {
28 awsRegion: "us-east-1",
29 accessKeyCreds: {
30 accessKeyId: awsAccessKeyId ?? "AKIATESTALCHEMY0000",
31 secretAccessKey: awsSecretAccessKey ?? "alchemy-test-secret",
32 },
33} as const;
34
35export const waitUntilGone = <A, R>(
36 get: Effect.Effect<A, NotFound | Forbidden | GcpOpError, R>,
37) =>
38 get.pipe(
39 Effect.as("found" as const),
40 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
41 Effect.repeat({
42 schedule: Schedule.spaced("2 seconds"),
43 until: (status) => status === "gone",
44 times: 10,
45 }),
46 );