1import * as Alchemy from "alchemy";
2import * as Hetzner from "alchemy/Hetzner";
3import * as Config from "effect/Config";
4import * as Effect from "effect/Effect";
5
6const DEFAULT_PUBLIC_KEY =
7 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINxKqNPbcpc0Hl9QguQ/M5OU1xk9YiNOtfeywcHiBu6d alchemy-hetzner-server-example";
8
9export default Alchemy.Stack(
10 "HetznerServerExample",
11 {
12 providers: Hetzner.providers(),
13 state: Alchemy.localState(),
14 },
15 Effect.gen(function* () {
16 const publicKey = yield* Config.String("SSH_PUBLIC_KEY").pipe(
17 Config.withDefault(DEFAULT_PUBLIC_KEY),
18 );
19 const key = yield* Hetzner.SshKey("deploy", { publicKey });
20 const server = yield* Hetzner.Server("box", {
21 serverType: "cx22",
22 image: "ubuntu-24.04",
23 location: "nbg1",
24 sshKeys: [key],
25 });
26
27 return {
28 ipv4: server.ipv4,
29 ipv6: server.ipv6,
30 };
31 }),
32);