DigitalOcean.Firewalls reference
Firewall
Section titled “Firewall”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.
Firewall: Creating a Firewall
Section titled “Firewall: Creating a Firewall”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"] }, ],});Firewall: Selecting droplets by tag
Section titled “Firewall: Selecting droplets by tag”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"] }, ],});Firewall: Denying traffic
Section titled “Firewall: Denying traffic”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"] }, ],});