Skip to content

DigitalOcean.Firewalls reference

Source: packages/digitalocean/src/Firewall.ts

A DigitalOcean Cloud Firewall. It filters traffic to droplets selected by id or by tag. Traffic that no rule allows is dropped. Every property updates in place.

A firewall has no ownership tag. Its tags prop selects droplets; it does not label the firewall. A generated name proves that alchemy created the firewall. A firewall with a name you chose and no prior state is Unowned and needs --adopt.

const host = yield* DigitalOcean.Droplet("app", {
region: "sfo3",
size: "s-2vcpu-4gb",
image: "ubuntu-24-04-x64",
});
yield* DigitalOcean.Firewall("edge", {
dropletIds: [host.dropletId],
inboundRules: [
{ protocol: "tcp", ports: "22", addresses: ["0.0.0.0/0", "::/0"] },
{ protocol: "tcp", ports: "80", addresses: ["0.0.0.0/0", "::/0"] },
{ protocol: "tcp", ports: "443", addresses: ["0.0.0.0/0", "::/0"] },
],
});
const host = yield* DigitalOcean.Droplet("web", {
region: "sfo3",
size: "s-2vcpu-4gb",
image: "ubuntu-24-04-x64",
tags: ["web"],
});
yield* DigitalOcean.Firewall("web-firewall", {
// `host.tags`, not `["web"]`: the firewall waits for the droplet that creates the tag.
tags: host.tags,
inboundRules: [
{ protocol: "tcp", ports: "443", addresses: ["0.0.0.0/0", "::/0"] },
],
});
yield* DigitalOcean.Firewall("edge", {
dropletIds: [host.dropletId],
inboundRules: [
{ protocol: "tcp", ports: "443", action: "deny", addresses: ["203.0.113.0/24"] },
{ protocol: "tcp", ports: "443", addresses: ["0.0.0.0/0", "::/0"] },
{ protocol: "icmp", ports: "0", addresses: ["0.0.0.0/0", "::/0"] },
],
});