Cloud.Firewall
A Better Stack Cloud firewall: a named set of inbound and outbound rules that you attach to servers. Rules only allow traffic; whatever no rule matches is dropped, in both directions. Firewalls are stateful (replies to an allowed connection pass) and free.
A firewall created through the API starts with one rule that allows all
outbound traffic and no inbound rule, so add at least an SSH rule before
attaching it to a server you need to reach. Rules are either listed
inline with rules (the whole set, converged on every change) or added
one by one as FirewallRule resources that take firewall.id.
name, rules and serverIds change in place; teamId and
availabilityZone replace the firewall. A firewall is deleted after the
servers this stack attached it to are detached.
Ownership. The API keeps no metadata for it, so the generated name (it ends
in the resource instance’s random suffix) is what identifies an object this stack
created: a create interrupted before its state was saved is found by that name on
the next deploy. An explicitly named object can’t be told apart from someone
else’s (it is taken over only with --adopt), and list returns every object.
Creating a firewall
Section titled “Creating a firewall”Inline rules (SSH and HTTPS in, everything out)
const web = yield* BetterStack.Cloud.Firewall("web", { rules: [ { direction: "inbound", protocol: "tcp", portFrom: 22, ipAddresses: ["0.0.0.0/0", "::/0"] }, { direction: "inbound", protocol: "tcp", portFrom: 443, ipAddresses: ["0.0.0.0/0", "::/0"] }, { direction: "outbound", protocol: "any", portFrom: 0, ipAddresses: ["0.0.0.0/0", "::/0"] }, ],});Rules as separate resources
const firewall = yield* BetterStack.Cloud.Firewall("web", { name: "web-public" });yield* BetterStack.Cloud.FirewallRule("ssh", { firewallId: firewall.id, direction: "inbound", protocol: "tcp", portFrom: 22, ipAddresses: ["0.0.0.0/0", "::/0"],});Attaching to servers
Section titled “Attaching to servers”Apply the firewall to a server
yield* BetterStack.Cloud.Firewall("app", { rules: [ { direction: "inbound", protocol: "tcp", portFrom: 80, portTo: 443, ipAddresses: ["0.0.0.0/0"] }, ], serverIds: [server.id],});Looking up an existing firewall
Section titled “Looking up an existing firewall”Reference a firewall by name
const existing = BetterStack.Cloud.Firewall.lookup({ name: "web-public" });availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
name string
The firewall's name, unique in your organization. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.
rules FirewallRuleSpec[]
The firewall's complete rule set, managed inline (like Hetzner's rules). When set, the firewall's rules are converged to exactly this list: missing rules are created, every other rule is deleted — including the allow-all outbound rule the API adds to every new firewall, so list an outbound rule if the servers must still connect out. An empty list drops all traffic. Leave it out to leave the rules alone: the firewall keeps its default outbound rule and you manage rules with [FirewallRule](/reference/cloud/firewallrule/) resources. Don't combine both on one firewall: the inline list deletes rules it doesn't name. Better Stack can't change a rule in place, so a changed entry is a delete plus a create of that one rule; unchanged rules are untouched.
serverIds string[]
Servers to attach the firewall to (like Hetzner's applyTo). Each attach and detach is its own API action, run in place. A server carries one firewall: attaching to a server that already has another one fails. Attach either here or with the server's own firewallIds, not both. The API doesn't list a firewall's servers, so only the servers named here are tracked; they are detached before the firewall is deleted.
teamId string
Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
id string always set
The firewall's ID, a UUID.
createdAt string
When the firewall was created.
name string
The firewall's name, unique in your organization.
rules FirewallRulesItem[]
The firewall's rules, oldest first. Add and remove rules with the firewall rule endpoints.
serverIds string[]
The servers this stack attached the firewall to (the API never returns them).
teamId string
The ID of the team that owns the firewall. betterstack team list shows it.
updatedAt string
When the firewall was last updated.
Lookup
Section titled “Lookup”Firewall.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
availabilityZone string
Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.