-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
113 lines (87 loc) · 3.18 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
99
100
101
102
103
104
105
106
107
108
109
110
111
// This script expects the aws key and secret as variables. This is necessary because we need access to the aws varialbes during the provisioning step.
// e.g. terraform apply -var 'access_key=......' -var 'secret_key=......' .
// So, first run 'terraform get'
// Finally, run the plan and apply steps to create the cluster. You can also provide the aws credentials with environmental variables like: TF_VAR_access_keys...
resource "aws_instance" "mesos-master" {
count = 1
ami = "${lookup(var.aws_amis, var.aws_region)}"
availability_zone = "eu-west-1b"
instance_type = "t2.large"
key_name = "${var.aws_key_name}"
subnet_id = "${aws_subnet.terraform.id}"
vpc_security_group_ids = ["${aws_security_group.terraform.id}"]
tags { Name = "mesos-master-${count.index}" }
connection {
user = "ubuntu"
key_file = "${var.private_key_file}"
}
provisioner "remote-exec" {
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done"
]
}
provisioner "file" {
source = "provision.sh"
destination = "/tmp/provision.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/provision.sh",
"/tmp/provision.sh localhost ${var.access_key} ${var.secret_key}"
]
}
provisioner "file" {
source = "provision-mesos-master.sh"
destination = "/tmp/provision-mesos.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/provision-mesos.sh",
"/tmp/provision-mesos.sh localhost"
]
}
}
resource "aws_instance" "mesos-agent" {
count = 3
ami = "${lookup(var.aws_amis, var.aws_region)}"
availability_zone = "eu-west-1b"
instance_type = "t2.large"
key_name = "${var.aws_key_name}"
subnet_id = "${aws_subnet.terraform.id}"
vpc_security_group_ids = ["${aws_security_group.terraform.id}"]
tags { Name = "mesos-agent-${count.index}" }
connection {
user = "ubuntu"
key_file = "${var.private_key_file}"
}
provisioner "remote-exec" {
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done"
]
}
provisioner "file" {
source = "provision.sh"
destination = "/tmp/provision.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/provision.sh",
"/tmp/provision.sh ${aws_instance.mesos-master.public_dns} ${var.access_key} ${var.secret_key}"
]
}
provisioner "file" {
source = "provision-mesos-slave.sh"
destination = "/tmp/provision-mesos.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/provision-mesos.sh",
"/tmp/provision-mesos.sh ${aws_instance.mesos-master.public_dns} localhost"
]
}
}
output "# SSH key" { value = "\nexport KEY=${var.private_key_file}" }
output "# Master" { value = "\nexport MASTER=${aws_instance.mesos-master.public_dns}" }
output "# Slave 0" { value = "\nexport SLAVE0=${aws_instance.mesos-agent.0.public_dns}" }
output "# Slave 1" { value = "\nexport SLAVE1=${aws_instance.mesos-agent.1.public_dns}" }
output "# Slave 2" { value = "\nexport SLAVE2=${aws_instance.mesos-agent.2.public_dns}" }