-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
84 lines (68 loc) · 2.5 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 "atlas_username" {}
variable "atlas_token" {}
variable "atlas_environment" {}
resource "aws_instance" "web" {
count = 3
ami = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.hashicorp-training.key_name}"
subnet_id = "${aws_subnet.hashicorp-training.id}"
vpc_security_group_ids = ["${aws_security_group.hashicorp-training.id}"]
tags { Name = "web-${count.index}" }
connection {
user = "ubuntu"
key_file = "${path.module}/${var.private_key_path}"
}
provisioner "file" {
source = "${path.module}/scripts/web/index.html.ctmpl"
destination = "/tmp/index.html.ctmpl"
}
provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/wait-for-ready.sh",
"${path.module}/scripts/consul-client/install.sh",
"${path.module}/scripts/consul-template/install.sh",
"${path.module}/scripts/web/install.sh",
]
}
provisioner "remote-exec" {
inline = [
"echo 'ATLAS_ENVIRONMENT=${var.atlas_environment}' | sudo tee -a /etc/service/consul &>/dev/null",
"echo 'ATLAS_TOKEN=${var.atlas_token}' | sudo tee -a /etc/service/consul &>/dev/null",
"echo 'NODE_NAME=web-${count.index}' | sudo tee -a /etc/service/consul &>/dev/null",
"sudo service consul restart",
]
}
}
resource "aws_instance" "haproxy" {
ami = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.hashicorp-training.key_name}"
subnet_id = "${aws_subnet.hashicorp-training.id}"
vpc_security_group_ids = ["${aws_security_group.hashicorp-training.id}"]
tags { Name = "haproxy" }
connection {
user = "ubuntu"
key_file = "${path.module}/${var.private_key_path}"
}
provisioner "file" {
source = "${path.module}/scripts/lb/haproxy.cfg.ctmpl"
destination = "/tmp/haproxy.cfg.ctmpl"
}
provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/wait-for-ready.sh",
"${path.module}/scripts/consul-client/install.sh",
"${path.module}/scripts/consul-template/install.sh",
"${path.module}/scripts/lb/install.sh",
]
}
provisioner "remote-exec" {
inline = [
"echo 'ATLAS_ENVIRONMENT=${var.atlas_environment}' | sudo tee -a /etc/service/consul &>/dev/null",
"echo 'ATLAS_TOKEN=${var.atlas_token}' | sudo tee -a /etc/service/consul &>/dev/null",
"echo 'NODE_NAME=haproxy' | sudo tee -a /etc/service/consul &>/dev/null",
"sudo service consul restart",
]
}
}