Terraform provider reference / resources / router_firewall_rule
fiberax_router_firewall_rule (Resource)
One access rule of a ROUTER's firewall.
Unlike fiberax_server_firewall, where the whole rule set is one resource, a router rule is a resource of its own: it is addressed by its number on the router (priority), and that number does not shift when a neighbouring rule is deleted. Rules are checked in ascending number order and the first matching rule wins.
Ordering across several rules is expressed with priority. Terraform creates resources in parallel, so rules created without a number get free numbers in an arbitrary order. Give each rule a priority when the order matters.
Rules created inside the router by hand are visible too. Those that use settings this API does not express (extra non-empty, editable = false) can be imported and deleted, but not changed; a hand-made rule that fits the fields here is changed like any other.
The first drop or reject rule also switches the router to stateful filtering (replies to established connections pass); that is a property of the router, not of the rule.
The rules filter traffic passing THROUGH the router, not traffic to the router itself: a drop on eth0 does not stop the router from answering a ping. A forwarded connection reaches the rules after the port forward - with the target's address and port: to let a forward 2222 -> 10.0.0.5:22 through, allow tcp to 10.0.0.5 port 22. A rule on the public port 2222 matches nothing, and together with a final "drop the rest" it cuts off your own forward.
Example Usage
# Access rules of a ROUTER. Each rule is a resource of its own, addressed by its
# number on the router; rules are checked in ascending number order and the
# first matching rule wins.
#
# Give rules a priority when the order matters: Terraform creates resources in
# parallel, and rules without a number get free numbers in an arbitrary order.
#
# The rules filter traffic passing THROUGH the router, not traffic to the router
# itself. A forwarded connection reaches them after the port forward, with the
# target's address and port: a forward 2222 -> 10.0.0.5:22 is let through by a
# rule for tcp to 10.0.0.5 port 22, not by one for port 2222.
resource "fiberax_router_firewall_rule" "ssh_from_office" {
server_id = fiberax_server.router.id
priority = 2010
action = "accept"
protocol = "tcp"
interface = "eth0" # the public side of the router
source = "203.0.113.0/24"
destination_port = "22"
description = "ssh from the office"
}
resource "fiberax_router_firewall_rule" "web" {
server_id = fiberax_server.router.id
priority = 2020
action = "accept"
protocol = "tcp"
interface = "eth0"
destination_port = "80,443"
description = "web"
}
# A port forward needs its own accept rule ABOVE the drop: the target's address
# and port, as the connection looks after the forward.
resource "fiberax_router_firewall_rule" "ssh_forward" {
server_id = fiberax_server.router.id
priority = 2030
action = "accept"
protocol = "tcp"
interface = "eth0"
destination = "10.0.0.5"
destination_port = "22"
description = "port forward 2222 to 10.0.0.5:22"
}
# The first drop or reject rule also switches the router to stateful filtering,
# so replies to connections allowed above keep passing. It does not close the
# router itself: traffic to the router does not pass these rules.
resource "fiberax_router_firewall_rule" "drop_the_rest" {
server_id = fiberax_server.router.id
priority = 2100
action = "drop"
interface = "eth0"
description = "everything else passing through from the internet"
}
Schema
Required
action(String)accept,droporreject.server_id(Number) The router the rule belongs to. A rule cannot move to another router: changing this field recreates the resource.
Optional
description(String) A note on the rule, up to 120 characters, without control characters.destination(String) IPv4 address or IPv4/prefix the traffic goes to. Not set means any. For a forwarded connection this is the forward's target address, not the router's public one.destination_port(String) Destination port, in the same form assource_port. Requiresprotocol. For a forwarded connection this is the target port (22for2222 -> 10.0.0.5:22), not the public one.enabled(Boolean) A disabled rule stays on the router and does nothing. Enabled by default.interface(String) Router interface the traffic arrives on, in the router's own names:eth0is the public side,eth1and up are the private networks (seeGET /v1/servers/{id}/router/networks). Not set means any interface. Tunnel interfaces are not accepted.priority(Number) Rule number, 2000 to 999000; lower numbers are checked first. Omit it and the platform takes the LOWEST free number of the row 2000, 2010, 2020, ... - so a rule without a number may land BEFORE the existing ones if a lower slot of the row is free.
The number cannot be changed on an existing rule, so setting a different one recreates the resource. A freed number of the row is taken again by the next rule without a number; a number outside the row (2015) is taken only when named explicitly.
protocol(String)tcp,udp,tcp_udporicmp. Not set means any protocol. A port requirestcp,udportcp_udp.source(String) IPv4 address or IPv4/prefix the traffic comes from. Not set means any.source_port(String) Source port AS TEXT: a number, a comma-separated list or a range WITH A DASH (22,80,443,10000-20000), up to 200 characters. Requiresprotocol.
Read-Only
editable(Boolean) False when the rule carries conditions this API cannot express (extrais non-empty): such a rule was created inside the router by hand and can only be read and deleted.extra(List of String) Conditions of the rule outside this API's model, in the router's own words. Empty for rules created through Terraform.id(Number) Rule number on the router - the same value aspriority.
Import
Import is supported using the following syntax:
The terraform import command can be used, for example:
# The import ID is the router's server ID and the rule number, separated by a comma. terraform import fiberax_router_firewall_rule.ssh_from_office 11102,2010
Generated from the provider schema for version 0.11.0. How to install the provider: Terraform provider.