Cloud.FirewallRule
One rule of a Better Stack Cloud Firewall: a direction, a
protocol, the addresses it applies to (CIDR) and a port range. Rules only
allow traffic. The change reaches every server using the firewall within
seconds.
Better Stack can’t update a rule: changing any prop (including
firewallId) creates the new rule first, then deletes the old one, so
the allowed traffic never has a gap. The API has no endpoint for one
rule, so the rule is read by listing its firewall’s rules. A rule whose
firewall was deleted is gone with it.
Use this resource to add rules one at a time (to a firewall whose other
rules are managed elsewhere, or alongside the default allow-all outbound
rule), or the firewall’s inline rules to manage the whole set; not both
on one firewall. The rule must live in its firewall’s availability zone:
pass availabilityZone: firewall.availabilityZone when the firewall is
not in the credentials’ zone.
There is nothing to adopt a rule by (rules have no name), so --adopt
never takes one over; a redeploy after a rule was deleted out of band
creates it again.
Zone. A child doesn’t take its zone from its parent: it uses its own
availabilityZone, else the credentials’ zone. When the parent lives in
another zone, pass the parent’s along (availabilityZone: parent.availabilityZone), or every call for it answers NotFound.
Opening ports
Section titled “Opening ports”SSH from anywhere
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"],});A port range from a private range
yield* BetterStack.Cloud.FirewallRule("app-ports", { firewallId: firewall.id, direction: "inbound", protocol: "tcp", portFrom: 8000, portTo: 8099, ipAddresses: ["10.0.0.0/8"],});Allow ping (a protocol without ports ignores portFrom)
yield* BetterStack.Cloud.FirewallRule("icmp", { firewallId: firewall.id, direction: "inbound", protocol: "icmp", portFrom: 0, ipAddresses: ["0.0.0.0/0"],});Looking up an existing rule
Section titled “Looking up an existing rule”Reference a rule by firewall and id
const existing = BetterStack.Cloud.FirewallRule.lookup({ firewallId: "6f1c0a52-5d4e-4bb1-9b8e-0c1a2b3c4d5e", id: "0d9f6c1e-2a3b-4c5d-8e9f-a0b1c2d3e4f5",});direction "inbound" | "outbound" | string required
Which traffic the rule matches. - inbound: The rule matches traffic that arrives at the server. - outbound: The rule matches traffic that leaves the server.
firewallId string required
The ID of the parent this firewall belongs to.
ipAddresses string[] required
The addresses the rule applies to, in CIDR notation, such as 10.0.0.0/8. Use 0.0.0.0/0 and ::/0 for every address. The list can't be empty.
portFrom number required
The first port of the range, from 0 to 65535. Every rule needs it. A protocol without ports, such as icmp, ignores it.
protocol "tcp" | "udp" | "icmp" | "gre" | "esp" | "any" | string required
The IP protocol the rule matches. any matches every protocol.
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.
portTo number
The last port of the range, from port_from to 65535. Leave it out to match only port_from.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
firewallId string always set
The firewall the rule belongs to. Always set on a rule this stack manages; a rule found by list carries it only when the API returns it.
id string always set
The rule's ID, a UUID.
direction "inbound" | "outbound"
Which traffic the rule matches. - inbound: The rule matches traffic that arrives at the server. - outbound: The rule matches traffic that leaves the server.
ipAddresses string[]
The addresses the rule applies to, in CIDR notation, such as 10.0.0.0/8. Use 0.0.0.0/0 and ::/0 for every address. The list can't be empty.
portFrom number
The first port of the range, from 0 to 65535. Every rule needs it. A protocol without ports, such as icmp, ignores it.
portTo number | null
The last port of the range, from port_from to 65535. Leave it out to match only port_from.
protocol "tcp" | "udp" | "icmp" | "gre" | "esp" | "any"
The IP protocol the rule matches. any matches every protocol.
Lookup
Section titled “Lookup”FirewallRule.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
firewallId string required
The firewall's ID.
id string required
The rule's ID.
availabilityZone string
Zone the firewall lives in, such as us-west-2a. Defaults to the credentials' zone.
See also
Section titled “See also”- Ownership. The API keeps no
metadatafor it and it has no generated name, so nothing marks it as this stack’s:listenumerates it under every parent, and a create interrupted before its state was saved is not recognised by the next deploy (which creates it again, or gets the API’s conflict when its identity is unique). - https://betterstack.com/docs/cloud/api/firewall-rules/create-firewall-rule/