Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions manifests/interface.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,60 @@
# @param config_dir
# Path to wireguard configuration files
define wireguard::interface (
Variant[Array,String] $address,
String $private_key,
Integer[1,65535] $listen_port,
Enum['present','absent'] $ensure = 'present',
Variant[Array,String] $address,
Variant[String, Deferred] $private_key,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would drop support for all Puppet version > 6 because the Type "Deferred" isn't known by Puppet 4/5.

I've implemented this without knowing someone else already did it. I think I found solution which supports Puppet 4/5/6.

Integer[1,65535] $listen_port,
Enum['present','absent'] $ensure = 'present',
Optional[Array[Struct[
{
'PublicKey' => String,
'PublicKey' => Variant[String,Deferred],
'AllowedIPs' => Optional[String],
'Endpoint' => Optional[String],
'PersistentKeepalive' => Optional[Integer],
}
]]] $peers = [],
Boolean $saveconfig = true,
Stdlib::Absolutepath $config_dir = '/etc/wireguard',
]]] $peers = [],
Boolean $saveconfig = true,
Stdlib::Absolutepath $config_dir = '/etc/wireguard',
) {

$interface_template = @(EOF)
# This file is managed by puppet
[Interface]
Address = <%= $address %>
<% if $saveconfig { -%>
SaveConfig = true
<% } -%>
PrivateKey = <%= $private_key %>
ListenPort = <%= $listen_port %>
<%- if $peers { -%>
# Peers
<% $peers.each |$peer| { -%>
[Peer]
<% $peer.each |$key,$value| { -%>
<% if $value { -%>
<%= $key %> = <%= $value %>
<% } -%>
<% } -%>
<% } -%>
<% } -%>
EOF


$content_hash = {
'address' => $address,
'private_key' => $private_key,
'listen_port' => $listen_port,
'peers' => $peers,
'saveconfig' => $saveconfig
}

file {"${config_dir}/${name}.conf":
ensure => $ensure,
mode => '0600',
owner => 'root',
group => 'root',
show_diff => false,
content => template("${module_name}/interface.conf.erb"),
content => Deferred('inline_epp', [$interface_template, $content_hash]),
notify => Service["wg-quick@${name}.service"],
}

Expand Down
24 changes: 0 additions & 24 deletions templates/interface.conf.erb

This file was deleted.