summaryrefslogtreecommitdiff
path: root/manifests/wireguard_peer.pp
blob: ea4c65a66a4c5f7a376afd7a2b7ecf5de4aeaa36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class profiles::wireguard_peer (
  Variant[String,Sensitive[String]] $private_key,
  Array[Hash] $peers,
  Stdlib::IP::Address $network_address,
  String $ifname = 'wg0',
) {
  include ::profiles::wireguard

  networking::networkd_instance { $ifname:
    type    => 'netdev',
    content => {
      'NetDev'        => {
        'Name'        => $ifname,
        'Kind'        => 'wireguard',
        'Description' => "WireGuard tunnel ${ifname}"
      },
      'WireGuard'     => {
        'PrivateKey' => $private_key,
      },
      'WireGuardPeer' => $peers,
    }
  }

  networking::networkd_instance { "${ifname}-network":
    type    => 'network',
    content => {
      'Match'   => {
        'Name' => $ifname,
      },
      'Network' => {
        'Address' => $network_address,
      },
    }
  }
}