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

Optional

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.

Read-Only

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.