Skip to content

Commit 2623fd2

Browse files
authored
Merge pull request #16 from unifio/yl-wip
Rollup of changes from WhistleLabs fork
2 parents 23b3d92 + 693dd41 commit 2623fd2

File tree

9 files changed

+113
-45
lines changed

9 files changed

+113
-45
lines changed

.circleci/config.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ common_steps: &common_steps
2929
name: "Test: verify plan"
3030
command: |
3131
bundle install
32-
33-
if [ "$TF_LEGACY" != "true" ]; then
34-
for example in $(ls -d examples/*/); do
35-
pushd $example
36-
terraform init
37-
popd
38-
done
39-
fi
40-
4132
bundle exec rake
4233
4334
- save_cache:
@@ -50,20 +41,6 @@ common_steps: &common_steps
5041
- /usr/local/bundle
5142

5243
jobs:
53-
0.8.8:
54-
docker:
55-
- image: circleci/ruby
56-
environment:
57-
- TF_VERSION: 0.8.8
58-
- TF_LEGACY: true
59-
steps: *common_steps
60-
0.9.11:
61-
docker:
62-
- image: circleci/ruby
63-
environment:
64-
- TF_VERSION: 0.9.11
65-
- TF_LEGACY: true
66-
steps: *common_steps
6744
0.10.7:
6845
docker:
6946
- image: circleci/ruby
@@ -82,8 +59,6 @@ workflows:
8259

8360
some_flow:
8461
jobs:
85-
- 0.8.8
86-
- 0.9.11
8762
- 0.10.7
8863
- 0.11.5
8964

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
## Unreleased
22

3-
## ???
3+
## 1.0.0
44

5+
#### IMPROVEMENTS:
6+
7+
Rollup fixes from whistle/terraform-aws-openvpn 0.0.9 - 0.2.5
8+
- Update server.conf with VPC DNS IP address
59
- Feature: Automatically push instance's subnet route into `server.conf`
610
- export `zone_id`, `dns_name` from aws_elb
711
- Fix the 4 subnet fixed mapping
812
- Fill in some examples
13+
- Add additional configuration options to Openvpn (#15)
14+
* Add eip and extra route capability
15+
* Update formatting
16+
* Fix the tag filter
17+
- OpenVPN CertGen RoleID Output (DEVOPS-1692)
18+
- OpenVPN RoleID Output (DEVOPS-1613)
19+
- Configure DNS entry in server.conf
20+
- Pin template provider version
21+
- Adding crl-verify to server.conf
22+
- Change permissions temporarily in user_data to avoid AMI change
23+
24+
25+
## 0.0.11
26+
27+
#### IMPROVEMENTS:
28+
- Terraform 0.8.x compatibility updates.
929

1030
## 0.0.10
1131

certs/main.tf

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# OpenVPN Server
22

3+
provider "template" {
4+
version = "~> 0.1"
5+
}
6+
37
## Creates IAM role & policies
48
resource "aws_iam_role" "role" {
59
name = "${var.stack_item_label}-${var.region}"
@@ -65,6 +69,7 @@ resource "aws_iam_role_policy" "tags" {
6569
"Effect": "Allow",
6670
"Action": [
6771
"ec2:CreateTags",
72+
"ec2:DescribeTags",
6873
"ec2:AssociateAddress",
6974
"ec2:DescribeAddresses",
7075
"ec2:DescribeInstances"
@@ -78,8 +83,8 @@ EOF
7883

7984
## Creates IAM instance profile
8085
resource "aws_iam_instance_profile" "profile" {
81-
name = "${var.stack_item_label}-${var.region}"
82-
roles = ["${aws_iam_role.role.name}"]
86+
name = "${var.stack_item_label}-${var.region}"
87+
role = "${aws_iam_role.role.name}"
8388
}
8489

8590
## Create elastic load balancer security group and rules
@@ -183,21 +188,37 @@ resource "aws_security_group_rule" "cluster_allow_icmp_in" {
183188
security_group_id = "${module.cluster.sg_id}"
184189
}
185190

191+
resource "aws_eip" "openvpn_eip" {
192+
count = "${var.assign_eip == "true" ? 1 : 0}"
193+
vpc = true
194+
195+
tags {
196+
application = "${var.stack_item_fullname}"
197+
managed_by = "terraform"
198+
Name = "${var.stack_item_label}"
199+
}
200+
}
201+
186202
## Creates instance user data
187203
data "template_file" "user_data" {
188204
template = "${file("${path.module}/templates/user_data.tpl")}"
189205

190206
vars {
191-
hostname = "${var.stack_item_label}"
192-
s3_bucket = "${var.s3_bucket}"
193-
s3_bucket_prefix = "${var.s3_bucket_prefix}"
194-
route_cidrs = "${var.route_cidrs}"
207+
additional_routes = "${var.additional_routes}"
208+
assign_eip = "${var.assign_eip}"
209+
hostname = "${var.stack_item_label}"
210+
s3_bucket = "${var.s3_bucket}"
211+
s3_bucket_prefix = "${var.s3_bucket_prefix}"
212+
stack_item_label = "${var.stack_item_label}"
213+
region = "${var.region}"
214+
route_cidrs = "${var.route_cidrs}"
215+
vpc_dns_ip = "${var.vpc_dns_ip}"
195216
}
196217
}
197218

198219
## Creates auto scaling cluster
199220
module "cluster" {
200-
source = "github.com/unifio/terraform-aws-asg?ref=v0.3.0//group"
221+
source = "github.com/unifio/terraform-aws-asg?ref=v0.3.1//group"
201222

202223
# Resource tags
203224
stack_item_label = "${var.stack_item_label}"
@@ -209,16 +230,18 @@ module "cluster" {
209230

210231
# LC parameters
211232
ami = "${coalesce(var.ami_custom, lookup(var.ami_region_lookup, var.region))}"
233+
ebs_optimized = "false"
234+
enable_monitoring = "true"
212235
instance_based_naming_enabled = "${var.instance_based_naming_enabled}"
213-
instance_type = "${var.instance_type}"
214236
instance_profile = "${aws_iam_instance_profile.profile.id}"
215-
user_data = "${data.template_file.user_data.rendered}"
237+
instance_type = "${var.instance_type}"
216238
key_name = "${var.key_name}"
239+
user_data = "${data.template_file.user_data.rendered}"
217240

218241
# ASG parameters
219242
max_size = 2
220243
min_size = 1
221244
hc_grace_period = 300
222245
min_elb_capacity = 1
223-
load_balancers = ["${aws_elb.elb.id}"]
246+
load_balancers = ["${split(",",aws_elb.elb.id)}"]
224247
}

certs/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ output "vpn_elb_dns_name" {
1515
output "vpn_elb_zone_id" {
1616
value = "${aws_elb.elb.zone_id}"
1717
}
18+
19+
output "role_id_openvpn" {
20+
value = "${aws_iam_role.role.unique_id}"
21+
}

certs/templates/user_data.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#cloud-config
22
runcmd:
3+
- export INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id`
34
- echo "OPENVPN_CERT_SOURCE=s3://${replace(s3_bucket,"/(/)+$/","")}/${replace(s3_bucket_prefix,"/^(/)+|(/)+$/","")}" > /etc/openvpn/get-openvpn-certs.env
5+
- if [ -n "${vpc_dns_ip}" ]; then echo "push \"dhcp-option DNS ${vpc_dns_ip}\"" >> /etc/openvpn/server.conf;fi
6+
- echo 'crl-verify /etc/openvpn/keys/crl.pem' >> /etc/openvpn/server.conf
47
- echo "push \"route $(ip route get 8.8.8.8| grep src| sed 's/.*src \(.*\)$/\1/g') 255.255.255.255 net_gateway\"" >> /etc/openvpn/server.conf
58
- echo "push \"route ${cidrhost(element(split(",",route_cidrs),1), 0)} ${cidrnetmask(element(split(",",route_cidrs),1))}\"" >> /etc/openvpn/server.conf
69
- echo "push \"route ${cidrhost(element(split(",",route_cidrs),2), 0)} ${cidrnetmask(element(split(",",route_cidrs),2))}\"" >> /etc/openvpn/server.conf
710
- echo "push \"route ${cidrhost(element(split(",",route_cidrs),3), 0)} ${cidrnetmask(element(split(",",route_cidrs),3))}\"" >> /etc/openvpn/server.conf
811
- echo "push \"route ${cidrhost(element(split(",",route_cidrs),4), 0)} ${cidrnetmask(element(split(",",route_cidrs),4))}\"" >> /etc/openvpn/server.conf
12+
- for route in `echo ${additional_routes} | tr ',' ' '`; do echo "push \"route $${route} 255.255.255.255\"" >> /etc/openvpn/server.conf;done
13+
- sed -i 's/\(ExecStartPost=.*chmod.*$\)/ExecStartPost=\/bin\/chown -R nobody:nogroup \/etc\/openvpn\n\1\n/g' /etc/systemd/system/get-openvpn-certs.service
14+
- systemctl daemon-reload
915
- systemctl start get-openvpn-certs
1016
- systemctl restart openvpn@server
1117
- systemctl restart iptables
18+
- if [ ${assign_eip} = 'true' ]; then for eip in `aws ec2 describe-tags --region=${region} --filters "Name=resource-type,Values=elastic-ip" "Name=value,Values=${stack_item_label}" | jq -r '.Tags[].ResourceId'`; do if [ `aws ec2 describe-addresses --allocation-id $${eip} --region=${region} | jq -r '.Addresses[].InstanceId'` = 'null' ]; then echo "$${eip} is available, assigning it to current instance";aws ec2 associate-address --instance-id "$${INSTANCE_ID}" --allocation-id $${eip} --region=${region};else echo "$${eip} is taken";fi; done;fi
1219

1320
output : { all : '| tee -a /var/log/cloud-init-output.log' }

certs/variables.tf

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ variable "subnets" {
2828
}
2929

3030
## OpenVPN parameters
31+
variable "additional_routes" {
32+
type = "string"
33+
description = "Additional routes to add to Openvpn Config"
34+
default = ""
35+
}
36+
3137
variable "ami_custom" {
3238
type = "string"
3339
description = "Custom AMI to utilize"
@@ -39,9 +45,10 @@ variable "ami_region_lookup" {
3945
type = "map"
4046

4147
default = {
42-
us-east-1 = "ami-d66995bb"
43-
ap-northeast-1 = "ami-4803ec29"
44-
us-west-2 = "ami-4308a323"
48+
us-east-1 = "ami-6934c804"
49+
ap-northeast-1 = "ami-b036d9d1"
50+
us-west-2 = "ami-530fa433"
51+
custom = ""
4552
}
4653
}
4754

@@ -51,6 +58,18 @@ variable "instance_based_naming_enabled" {
5158
default = ""
5259
}
5360

61+
variable "assign_eip" {
62+
type = "string"
63+
description = "Boolean to determine if Elastic IP should be assigned to host"
64+
default = "false"
65+
}
66+
67+
variable "eip_tag" {
68+
type = "string"
69+
description = "Tag used to lookup Elastic IP to assign"
70+
default = ""
71+
}
72+
5473
variable "instance_type" {
5574
type = "string"
5675
description = "EC2 instance type to associate with the launch configuration."
@@ -81,14 +100,20 @@ variable "s3_bucket_prefix" {
81100
default = ""
82101
}
83102

84-
variable "vpn_whitelist" {
103+
variable "ssh_whitelist" {
85104
type = "string"
86-
description = "Limit VPN access to the designated list of CIDRs"
105+
description = "Limit SSH access to the designated list of CIDRs"
87106
default = "0.0.0.0/0"
88107
}
89108

90-
variable "ssh_whitelist" {
109+
variable "vpc_dns_ip" {
91110
type = "string"
92-
description = "Limit SSH access to the designated list of CIDRs"
111+
description = "DNS IP address for the VPC."
112+
default = ""
113+
}
114+
115+
variable "vpn_whitelist" {
116+
type = "string"
117+
description = "Limit VPN access to the designated list of CIDRs"
93118
default = "0.0.0.0/0"
94119
}

examples/server/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ module "openvpn_server" {
2424
route_cidrs = "${var.route_cidrs}"
2525
s3_bucket = "${var.s3_bucket}"
2626
s3_bucket_prefix = "${var.s3_bucket_prefix}"
27+
28+
assign_eip = "true"
29+
eip_tag = "openvpn-instance"
30+
vpc_dns_ip = "1.1.1.1"
2731
}

generate-certs/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# OpenVPN Certificate Generator
22

3+
provider "template" {
4+
version = "~> 0.1"
5+
}
6+
37
## Creates IAM role & policies
48
resource "aws_iam_role" "role" {
59
name = "${var.stack_item_label}-${var.region}"
@@ -66,6 +70,7 @@ resource "aws_iam_role_policy" "tags" {
6670
"Effect": "Allow",
6771
"Action": [
6872
"ec2:CreateTags",
73+
"ec2:DescribeTags",
6974
"ec2:AssociateAddress",
7075
"ec2:DescribeAddresses",
7176
"ec2:DescribeInstances"
@@ -79,8 +84,8 @@ EOF
7984

8085
## Creates IAM instance profile
8186
resource "aws_iam_instance_profile" "profile" {
82-
name = "${var.stack_item_label}-${var.region}"
83-
roles = ["${aws_iam_role.role.name}"]
87+
name = "${var.stack_item_label}-${var.region}"
88+
role = "${aws_iam_role.role.name}"
8489
}
8590

8691
## Creates security group rules

generate-certs/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Outputs
2+
3+
output "role_id_certgen" {
4+
value = "${aws_iam_role.role.unique_id}"
5+
}

0 commit comments

Comments
 (0)