Converted router configuration file from .conf to JSON.
This commit is contained in:
1 parent
c423ea9347
commit
b18947ed9b
18 files changed
+285
-396
No files matched your search
+20
-23
@@ -6,29 +6,26 @@ locals {
|
||||
supply_pki = var.ca_cert_file != ""
|
||||
|
||||
cloud_init_vars = {
|
||||
hostname = var.name
|
||||
fqdn = var.local_fqdn
|
||||
repo_url = var.repo_url
|
||||
repo_gpg_key = data.http.repo_gpg_key.response_body
|
||||
ubuntu_codename = var.ubuntu_codename
|
||||
platform = "azure"
|
||||
mode = "auto"
|
||||
external_interface = ""
|
||||
internal_interface = ""
|
||||
local_id_mode = var.local_id_mode
|
||||
local_cidrs = var.local_cidrs
|
||||
int_addr = ""
|
||||
int_gateway_ip = ""
|
||||
remote_addrs = var.remote_addrs
|
||||
remote_id = var.remote_id
|
||||
remote_cidrs = var.remote_cidrs
|
||||
psk_b64 = base64encode(var.psk)
|
||||
p2s_enabled = var.p2s_enabled
|
||||
p2s_address_pool = var.p2s_address_pool
|
||||
p2s_ca_name = "VPN Router CA"
|
||||
wg_enabled = var.wireguard_enabled
|
||||
wg_address = var.wireguard_address
|
||||
wg_listen_port = var.wireguard_listen_port
|
||||
hostname = var.name
|
||||
fqdn = var.local_fqdn
|
||||
repo_url = var.repo_url
|
||||
repo_gpg_key = data.http.repo_gpg_key.response_body
|
||||
ubuntu_codename = var.ubuntu_codename
|
||||
|
||||
# Contents of /etc/vpn-router/vpn-router.json.
|
||||
config = {
|
||||
general = { platform = "azure", mode = "auto" }
|
||||
wan = { local_fqdn = var.local_fqdn, local_id_mode = var.local_id_mode }
|
||||
local = { cidrs = [for c in split(",", var.local_cidrs) : trimspace(c) if trimspace(c) != ""] }
|
||||
remote = {
|
||||
addrs = [for a in split(",", var.remote_addrs) : trimspace(a) if trimspace(a) != ""]
|
||||
id = var.remote_id
|
||||
cidrs = local.remote_cidr_list
|
||||
psk = var.psk
|
||||
}
|
||||
p2s = { enabled = var.p2s_enabled, address_pool = var.p2s_address_pool, ca_name = "VPN Router CA" }
|
||||
wireguard = { enabled = var.wireguard_enabled, address = var.wireguard_address, listen_port = var.wireguard_listen_port }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,42 +22,11 @@ apt:
|
||||
write_files:
|
||||
# The configuration file. Created here before the package is installed, so
|
||||
# postinst leaves it alone.
|
||||
- path: /etc/vpn-router/vpn-router.conf
|
||||
- path: /etc/vpn-router/vpn-router.json
|
||||
permissions: '0600'
|
||||
owner: root:root
|
||||
content: |
|
||||
[general]
|
||||
platform = ${platform}
|
||||
mode = ${mode}
|
||||
|
||||
[interfaces]
|
||||
external = ${external_interface}
|
||||
internal = ${internal_interface}
|
||||
|
||||
[wan]
|
||||
local_fqdn = ${fqdn}
|
||||
local_id_mode = ${local_id_mode}
|
||||
|
||||
[local]
|
||||
cidrs = ${local_cidrs}
|
||||
int_addr = ${int_addr}
|
||||
int_gateway_ip = ${int_gateway_ip}
|
||||
|
||||
[remote]
|
||||
addrs = ${remote_addrs}
|
||||
id = ${remote_id}
|
||||
cidrs = ${remote_cidrs}
|
||||
psk_b64 = ${psk_b64}
|
||||
|
||||
[p2s]
|
||||
enabled = ${p2s_enabled}
|
||||
address_pool = ${p2s_address_pool}
|
||||
ca_name = ${p2s_ca_name}
|
||||
|
||||
[wireguard]
|
||||
enabled = ${wg_enabled}
|
||||
address = ${wg_address}
|
||||
listen_port = ${wg_listen_port}
|
||||
${jsonencode(config)}
|
||||
|
||||
- path: /etc/vpn-router/pki/ca_cert.pem
|
||||
permissions: '0644'
|
||||
|
||||
@@ -28,42 +28,11 @@ apt:
|
||||
write_files:
|
||||
# The configuration file. Created here before the package is installed, so
|
||||
# postinst leaves it alone.
|
||||
- path: /etc/vpn-router/vpn-router.conf
|
||||
- path: /etc/vpn-router/vpn-router.json
|
||||
permissions: '0600'
|
||||
owner: root:root
|
||||
content: |
|
||||
[general]
|
||||
platform = ${platform}
|
||||
mode = ${mode}
|
||||
|
||||
[interfaces]
|
||||
external = ${external_interface}
|
||||
internal = ${internal_interface}
|
||||
|
||||
[wan]
|
||||
local_fqdn = ${fqdn}
|
||||
local_id_mode = ${local_id_mode}
|
||||
|
||||
[local]
|
||||
cidrs = ${local_cidrs}
|
||||
int_addr = ${int_addr}
|
||||
int_gateway_ip = ${int_gateway_ip}
|
||||
|
||||
[remote]
|
||||
addrs = ${remote_addrs}
|
||||
id = ${remote_id}
|
||||
cidrs = ${remote_cidrs}
|
||||
psk_b64 = ${psk_b64}
|
||||
|
||||
[p2s]
|
||||
enabled = ${p2s_enabled}
|
||||
address_pool = ${p2s_address_pool}
|
||||
ca_name = ${p2s_ca_name}
|
||||
|
||||
[wireguard]
|
||||
enabled = ${wg_enabled}
|
||||
address = ${wg_address}
|
||||
listen_port = ${wg_listen_port}
|
||||
${jsonencode(config)}
|
||||
|
||||
package_update: true
|
||||
|
||||
|
||||
+20
-23
@@ -6,29 +6,26 @@ locals {
|
||||
supply_pki = var.ca_cert_file != ""
|
||||
|
||||
cloud_init_vars = {
|
||||
hostname = var.name
|
||||
fqdn = var.local_fqdn
|
||||
repo_url = var.repo_url
|
||||
repo_gpg_key = data.http.repo_gpg_key.response_body
|
||||
ubuntu_codename = var.ubuntu_codename
|
||||
platform = "gcp"
|
||||
mode = "auto"
|
||||
external_interface = ""
|
||||
internal_interface = ""
|
||||
local_id_mode = var.local_id_mode
|
||||
local_cidrs = var.local_cidrs
|
||||
int_addr = ""
|
||||
int_gateway_ip = ""
|
||||
remote_addrs = var.remote_addrs
|
||||
remote_id = var.remote_id
|
||||
remote_cidrs = var.remote_cidrs
|
||||
psk_b64 = base64encode(var.psk)
|
||||
p2s_enabled = var.p2s_enabled
|
||||
p2s_address_pool = var.p2s_address_pool
|
||||
p2s_ca_name = "VPN Router CA"
|
||||
wg_enabled = var.wireguard_enabled
|
||||
wg_address = var.wireguard_address
|
||||
wg_listen_port = var.wireguard_listen_port
|
||||
hostname = var.name
|
||||
fqdn = var.local_fqdn
|
||||
repo_url = var.repo_url
|
||||
repo_gpg_key = data.http.repo_gpg_key.response_body
|
||||
ubuntu_codename = var.ubuntu_codename
|
||||
|
||||
# Contents of /etc/vpn-router/vpn-router.json.
|
||||
config = {
|
||||
general = { platform = "gcp", mode = "auto" }
|
||||
wan = { local_fqdn = var.local_fqdn, local_id_mode = var.local_id_mode }
|
||||
local = { cidrs = [for c in split(",", var.local_cidrs) : trimspace(c) if trimspace(c) != ""] }
|
||||
remote = {
|
||||
addrs = [for a in split(",", var.remote_addrs) : trimspace(a) if trimspace(a) != ""]
|
||||
id = var.remote_id
|
||||
cidrs = local.remote_cidr_list
|
||||
psk = var.psk
|
||||
}
|
||||
p2s = { enabled = var.p2s_enabled, address_pool = var.p2s_address_pool, ca_name = "VPN Router CA" }
|
||||
wireguard = { enabled = var.wireguard_enabled, address = var.wireguard_address, listen_port = var.wireguard_listen_port }
|
||||
}
|
||||
}
|
||||
|
||||
cloud_init_rendered = local.supply_pki ? templatefile("${path.module}/../cloud-init-with-pki.yaml.tpl", merge(local.cloud_init_vars, {
|
||||
|
||||
+43
-37
@@ -10,18 +10,19 @@ set -e
|
||||
|
||||
DEB="${DEB:-./vpn-router_1.0.0-1_all.deb}"
|
||||
|
||||
# List values are JSON arrays.
|
||||
PLATFORM="${PLATFORM:-generic}"
|
||||
MODE="${MODE:-manual}"
|
||||
EXTERNAL_INTERFACE="${EXTERNAL_INTERFACE:-eth0}"
|
||||
INTERNAL_INTERFACE="${INTERNAL_INTERFACE:-eth1}"
|
||||
LOCAL_FQDN="${LOCAL_FQDN:-router.example.com}"
|
||||
LOCAL_ID_MODE="${LOCAL_ID_MODE:-fqdn}"
|
||||
LOCAL_CIDRS="${LOCAL_CIDRS:-10.0.0.0/24}"
|
||||
LOCAL_CIDRS="${LOCAL_CIDRS:-[\"10.0.0.0/24\"]}"
|
||||
INT_ADDR="${INT_ADDR:-10.1.1.4}"
|
||||
INT_GATEWAY_IP="${INT_GATEWAY_IP:-10.1.1.1}"
|
||||
REMOTE_ADDRS="${REMOTE_ADDRS:-peer.example.net}"
|
||||
REMOTE_ADDRS="${REMOTE_ADDRS:-[\"peer.example.net\"]}"
|
||||
REMOTE_ID="${REMOTE_ID:-peer.example.net}"
|
||||
REMOTE_CIDRS="${REMOTE_CIDRS:-192.168.0.0/24}"
|
||||
REMOTE_CIDRS="${REMOTE_CIDRS:-[\"192.168.0.0/24\"]}"
|
||||
PSK="${PSK:-change-me}"
|
||||
P2S_ENABLED="${P2S_ENABLED:-false}"
|
||||
P2S_ADDRESS_POOL="${P2S_ADDRESS_POOL:-172.16.0.0/24}"
|
||||
@@ -30,42 +31,47 @@ WG_ENABLED="${WG_ENABLED:-false}"
|
||||
WG_ADDRESS="${WG_ADDRESS:-}"
|
||||
WG_LISTEN_PORT="${WG_LISTEN_PORT:-51820}"
|
||||
|
||||
# Write the configuration before installing, so postinst leaves it alone.
|
||||
# Write the configuration before installing, so postinst leaves it alone. The
|
||||
# pre-shared key goes to its own file, so it needs no JSON escaping.
|
||||
install -d -m 0755 /etc/vpn-router
|
||||
umask 077
|
||||
cat > /etc/vpn-router/vpn-router.conf <<EOF
|
||||
[general]
|
||||
platform = ${PLATFORM}
|
||||
mode = ${MODE}
|
||||
|
||||
[interfaces]
|
||||
external = ${EXTERNAL_INTERFACE}
|
||||
internal = ${INTERNAL_INTERFACE}
|
||||
|
||||
[wan]
|
||||
local_fqdn = ${LOCAL_FQDN}
|
||||
local_id_mode = ${LOCAL_ID_MODE}
|
||||
|
||||
[local]
|
||||
cidrs = ${LOCAL_CIDRS}
|
||||
int_addr = ${INT_ADDR}
|
||||
int_gateway_ip = ${INT_GATEWAY_IP}
|
||||
|
||||
[remote]
|
||||
addrs = ${REMOTE_ADDRS}
|
||||
id = ${REMOTE_ID}
|
||||
cidrs = ${REMOTE_CIDRS}
|
||||
psk_b64 = $(printf %s "$PSK" | base64 -w0)
|
||||
|
||||
[p2s]
|
||||
enabled = ${P2S_ENABLED}
|
||||
address_pool = ${P2S_ADDRESS_POOL}
|
||||
ca_name = ${P2S_CA_NAME}
|
||||
|
||||
[wireguard]
|
||||
enabled = ${WG_ENABLED}
|
||||
address = ${WG_ADDRESS}
|
||||
listen_port = ${WG_LISTEN_PORT}
|
||||
printf %s "$PSK" > /etc/vpn-router/psk
|
||||
cat > /etc/vpn-router/vpn-router.json <<EOF
|
||||
{
|
||||
"general": {
|
||||
"platform": "${PLATFORM}",
|
||||
"mode": "${MODE}"
|
||||
},
|
||||
"interfaces": {
|
||||
"external": "${EXTERNAL_INTERFACE}",
|
||||
"internal": "${INTERNAL_INTERFACE}"
|
||||
},
|
||||
"wan": {
|
||||
"local_fqdn": "${LOCAL_FQDN}",
|
||||
"local_id_mode": "${LOCAL_ID_MODE}"
|
||||
},
|
||||
"local": {
|
||||
"cidrs": ${LOCAL_CIDRS},
|
||||
"int_addr": "${INT_ADDR}",
|
||||
"int_gateway_ip": "${INT_GATEWAY_IP}"
|
||||
},
|
||||
"remote": {
|
||||
"addrs": ${REMOTE_ADDRS},
|
||||
"id": "${REMOTE_ID}",
|
||||
"cidrs": ${REMOTE_CIDRS},
|
||||
"psk_file": "/etc/vpn-router/psk"
|
||||
},
|
||||
"p2s": {
|
||||
"enabled": ${P2S_ENABLED},
|
||||
"address_pool": "${P2S_ADDRESS_POOL}",
|
||||
"ca_name": "${P2S_CA_NAME}"
|
||||
},
|
||||
"wireguard": {
|
||||
"enabled": ${WG_ENABLED},
|
||||
"address": "${WG_ADDRESS}",
|
||||
"listen_port": ${WG_LISTEN_PORT}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
umask 022
|
||||
|
||||
|
||||
Reference in new issue
Block a user