-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.tf
71 lines (55 loc) · 1.29 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
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
data "aws_ami" "oracle" {
most_recent = true
filter {
name = "name"
values = ["OL7.6-x86_64-HVM-2019-01-29"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["131827586825"] # Canonical
}
resource "aws_instance" "pritunl" {
ami = data.aws_ami.oracle.id
instance_type = var.instance_type
key_name = var.aws_key_name
user_data = file("${path.module}/provision.sh")
vpc_security_group_ids = [
aws_security_group.pritunl.id,
aws_security_group.allow_from_office.id,
]
subnet_id = var.public_subnet_id
associate_public_ip_address = false
tags = "${
merge(
map("Name", format("%s-%s", var.resource_name_prefix, "vpn")),
var.tags,
)
}"
provisioner "remote-exec" {
inline = [
"sleep 60",
"sudo pritunl setup-key",
]
}
}
data "aws_instance" "pritunl_loaded" {
depends_on = [
aws_instance.pritunl
]
filter {
name = "image-id"
values = [data.aws_ami.oracle.id]
}
filter {
name = "tag:Name"
values = [format("%s-%s", var.resource_name_prefix, "vpn")]
}
}
resource "aws_eip" "pritunl" {
instance = "${aws_instance.pritunl.id}"
vpc = true
}