-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
84 lines (76 loc) · 1.75 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
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "region" {}
variable "route53_domain_name" {}
variable "base_image" {}
variable "instance_type" {}
variable "ssh_key" {}
variable "ssh_key_name" {}
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.region}"
}
data "aws_route53_zone" "main" {
name = "${var.route53_domain_name}"
}
resource "aws_security_group" "vpn" {
name = "VPN instance"
description = "Open inbound SSH"
ingress {
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
protocol = "udp"
from_port = 1194
to_port = 1194
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "vpn" {
ami = "${var.base_image}"
instance_type = "${var.instance_type}"
associate_public_ip_address = "true"
security_groups = ["${aws_security_group.vpn.name}"]
key_name = "${var.ssh_key_name}"
tags {
Name = "docker-openvpn"
created_by = "terraform"
}
provisioner "file" {
source = "./files_to_provision/"
destination = "/tmp"
connection {
host = "${self.public_ip}"
user = "fedora"
private_key = "${file(var.ssh_key)}"
}
}
provisioner "remote-exec" {
scripts = [ "./scripts/configure_node.sh" ]
connection {
host = "${self.public_ip}"
user = "fedora"
private_key = "${file(var.ssh_key)}"
}
}
}
resource "aws_route53_record" "vpn"{
zone_id = "${data.aws_route53_zone.main.id}"
name = "vpn"
type = "A"
ttl = "300"
records = ["${aws_instance.vpn.public_ip}"]
}
output "address" {
value = "${aws_instance.vpn.public_ip}"
}