-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement VPN configuration using a 'terraform module'.
- Loading branch information
Showing
9 changed files
with
184 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# File:: vpn.tf | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# Uses 'VPN module' to configure a OpenVPN server on the remote instance | ||
# | ||
|
||
module "vpn" { | ||
source = "../modules/vpn" | ||
vpn_ip = "${module.nat.public_ip}" | ||
vpn_port = "${var.vpn_port}" | ||
vpc_cidr = "${var.vpc_cidr}" | ||
ssh_user = "${var.ssh_user}" | ||
#-- assuming 'private key name' by removing the '.pub' extension | ||
private_key_file = "${replace(var.ssh_public_key_file, ".pub", "")}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"openvpn": { | ||
"tar_path": "/home/${client_prefix}/keys", | ||
"script_security": 2, | ||
"push_routes": [ | ||
"${push_routes_array}" | ||
], | ||
"gateway": "${gateway_address}", | ||
"config": { | ||
"proto": "${vpn_proto}", | ||
"cipher": "AES-256-CBC", | ||
"port": ${vpn_port} | ||
}, | ||
"client_prefix": "${client_prefix}", | ||
"signing_ca_cert": "/etc/openvpn/keys/${client_prefix}.crt", | ||
"signing_ca_key": "/etc/openvpn/keys/${client_prefix}.key", | ||
"key": { | ||
"country": "RO", | ||
"province": "CJ", | ||
"city": "Cluj Napoca", | ||
"org": "Endava", | ||
"email": "[email protected]" | ||
} | ||
}, | ||
"run_list": [ | ||
"recipe[en_deploy_openvpn]" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#cloud-config | ||
hostname: NAT-VPN | ||
manage_etc_hosts: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# Module:: VPN | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# VPN module configures a OpenVPN server on the remote instance | ||
# | ||
|
||
data "template_file" "custom_attrib" { | ||
template = "${file("../files/provisioning/vpn_custom_attrib.tpl")}" | ||
vars { | ||
push_routes_array = "${cidrhost(var.vpc_cidr, 0)} ${cidrnetmask(var.vpc_cidr)}" | ||
gateway_address = "${var.vpn_ip}" | ||
vpn_port = "${var.vpn_port}" | ||
vpn_proto = "${var.vpn_proto}" | ||
client_prefix = "devops_cluj" | ||
} | ||
} | ||
|
||
#-- Currently, as of terraform 0.9.2, it doesn't allow us | ||
#-- to specify a common connection block to be used for all | ||
#-- the provisioners, so we have to repeat that block for | ||
#-- each provisioner | ||
|
||
resource "null_resource" "preparation" { | ||
triggers { | ||
always = "${uuid()}" | ||
} | ||
#-- | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"rm -rf /home/${var.ssh_user}/provision", | ||
"curl -L --create-dirs -o /home/${var.ssh_user}/provision/en_ovpn.tar.gz https://github.com/xxmitsu/en_ovpn/archive/EN_OVPN-${var.ovpn_cookbook_ver}.tar.gz", | ||
"tar -xzf /home/${var.ssh_user}/provision/en_ovpn.tar.gz -C /home/${var.ssh_user}/provision/", | ||
"cat > /home/centos/provision/en_ovpn-EN_OVPN-${var.ovpn_cookbook_ver}/provision/custom_attrib.json <<EOL\n${data.template_file.custom_attrib.rendered}\nEOL", | ||
"/home/centos/provision/en_ovpn-EN_OVPN-${var.ovpn_cookbook_ver}/provision/provision.sh /home/centos/provision/en_ovpn-EN_OVPN-${var.ovpn_cookbook_ver}/provision/" | ||
] | ||
connection { | ||
host = "${var.vpn_ip}" | ||
user = "${var.ssh_user}" | ||
timeout = "30s" | ||
private_key = "${file(var.private_key_file)}" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Project Name:: en_infra_aws | ||
# Module:: VPN - variables file | ||
# | ||
# Copyright (C) 2017 - Present | ||
# Author: 'Mihai Vultur <mihai.vultur@___.com>' | ||
# | ||
# All rights reserved | ||
# | ||
# Description: | ||
# VPN module specific variables | ||
# | ||
|
||
variable "ssh_user" { | ||
description = "Name of the ssh user used for configuring the remote instances" | ||
type = "string" | ||
} | ||
|
||
variable "private_key_file" { | ||
description = "Path to private key file used in combination with ssh_user" | ||
} | ||
|
||
variable "ovpn_cookbook_ver" { | ||
description = "Version of the custom chef cookbook used to configure the OpenVPN service." | ||
default = "1.1.0" | ||
} | ||
|
||
variable "vpn_ip" { | ||
description = "IP Address of the OpenVPN server" | ||
} | ||
|
||
variable "vpn_port" { | ||
description = "Port that the OpenVPN server will listen to." | ||
default = "1194" | ||
} | ||
|
||
variable "vpn_proto" { | ||
description = "Protocol used for VPN transport: 'udp' or 'tcp'." | ||
default = "tcp" | ||
} | ||
|
||
variable "vpc_cidr" { | ||
description = "CIDR block we want the OpenVPN server to add a route to facilitate traffic." | ||
} |