Skip to content

DigitalOcean.SSH Keys reference

Source: packages/digitalocean/src/SshKey.ts

An SSH public key registered on the DigitalOcean team. Droplets created with it accept the key for root. The fingerprint of the key material identifies the key, and DigitalOcean allows one registration per key material. A change to the material replaces the resource. A change to name updates in place.

A key has no ownership tag, so only the name alchemy generates for it proves that alchemy registered it. The same material registered under any other name is Unowned and needs --adopt, so omitting name does not help.

When new material is still an unresolved Output at plan time, as the public key of a replaced KeyPair is, the first deploy fails with SshKeyMaterialChanged and the next one replaces the key.

Register a deploy key and create a droplet with it

const key = yield* DigitalOcean.SshKey("deploy-key", {
publicKey: yield* Config.String("SSH_PUBLIC_KEY"),
});
const host = yield* DigitalOcean.Droplet("app", {
region: "sfo3",
size: "s-2vcpu-4gb",
image: "ubuntu-24-04-x64",
sshKeys: [key.fingerprint],
});

Generate the key pair in the stack

const pair = yield* Alchemy.KeyPair("deploy-key-pair");
const key = yield* DigitalOcean.SshKey("deploy-key", {
publicKey: pair.publicKey,
});