-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.tf
98 lines (83 loc) · 2.07 KB
/
main.tf
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//data "aws_ami" "ubuntu" {
// most_recent = true
//
// filter {
// name = "name"
// values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
// values = ["paravirtual"]
// }
//
// owners = ["099720109477"]
//}
resource "aws_security_group" "openvpn" {
name = "${var.name}"
vpc_id = "${var.vpc_id}"
description = "OpenVPN security group"
tags {
Name = "${var.name}"
}
ingress {
protocol = -1
from_port = 0
to_port = 0
cidr_blocks = ["${var.vpc_cidr}"]
}
# For OpenVPN Client Web Server & Admin Web UI
ingress {
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
protocol = "udp"
from_port = 1194
to_port = 1194
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = -1
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_ebs_volume" "openvpn_data" {
availability_zone = "${var.ebs_region}"
size = "${var.ebs_size}"
encrypted = true
lifecycle {
prevent_destroy = false
}
}
resource "aws_instance" "openvpn" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${element(split(",", var.public_subnet_ids), count.index)}"
vpc_security_group_ids = ["${aws_security_group.openvpn.id}"]
tags {
Name = "${var.name}"
}
}
resource "aws_volume_attachment" "ebs_att" {
device_name = "/dev/sdh"
instance_id = "${aws_instance.openvpn.id}"
volume_id = "${aws_ebs_volume.openvpn_data.id}"
provisioner "local-exec" {
command = "ansible-playbook --private-key ~/.ssh/id_rsa.pub -i '${aws_instance.openvpn.public_ip},' config/ansible/openvpn.yml"
}
}
resource "aws_route53_record" "openvpn" {
zone_id = "${var.route_zone_id}"
name = "vpn.${var.domain}"
type = "A"
ttl = "300"
records = ["${aws_instance.openvpn.public_ip}"]
}