Terraform provider reference / resources / router_wireguard_device

fiberax_router_wireguard_device (Resource)

A device (peer) of a router's WireGuard tunnel.

The private key never leaves the device. Generate the key pair on the device (or in Terraform with wireguard_asymmetric_key from the OJFord/wireguard provider) and give the platform the PUBLIC half only. Everything the device needs for its configuration is read back: its address here, and public_key, endpoint, allowed_ips, dns and keepalive of the tunnel from fiberax_router_wireguard.

The tunnel must be enabled before a device is added: reference the tunnel resource so that Terraform orders them (server_id = fiberax_router_wireguard.x.server_id). Up to ten devices per tunnel. The only changeable field is name; a new key means a new device.

Example Usage

# A device (peer) of the router's WireGuard tunnel.
#
# THE PRIVATE KEY NEVER LEAVES THE DEVICE: the platform receives the public half only.
# Generate the pair on the device with `wg genkey | tee private.key | wg pubkey`,
# or in Terraform with the OJFord/wireguard provider as below.
terraform {
  required_providers {
    fiberax   = { source = "fiberax/fiberax" }
    wireguard = { source = "OJFord/wireguard" }
  }
}

resource "wireguard_asymmetric_key" "laptop" {}

resource "fiberax_router_wireguard_device" "laptop" {
  # Referencing the tunnel resource makes Terraform enable it before adding the device.
  server_id  = fiberax_router_wireguard.vpn.server_id
  name       = "laptop"
  public_key = wireguard_asymmetric_key.laptop.public_key
}

# The device configuration, assembled from the tunnel and the device: nothing here
# comes from the platform's secrets. Feed it to `wg-quick`.
output "laptop_wg_conf" {
  sensitive = true
  value     = <<-EOT
    [Interface]
    PrivateKey = ${wireguard_asymmetric_key.laptop.private_key}
    Address = ${fiberax_router_wireguard_device.laptop.address}/${split("/", fiberax_router_wireguard.vpn.subnet)[1]}
    DNS = ${fiberax_router_wireguard.vpn.dns}

    [Peer]
    PublicKey = ${fiberax_router_wireguard.vpn.public_key}
    Endpoint = ${fiberax_router_wireguard.vpn.endpoint}
    AllowedIPs = ${join(", ", fiberax_router_wireguard.vpn.allowed_ips)}
    PersistentKeepalive = ${fiberax_router_wireguard.vpn.keepalive}
  EOT
}

Schema

Required

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 device ID, separated by a comma.
terraform import fiberax_router_wireguard_device.laptop 11102,dev1

Generated from the provider schema for version 0.3.0. How to install the provider: Terraform provider.