-
Notifications
You must be signed in to change notification settings - Fork 2
/
runners.tf
71 lines (61 loc) · 2.38 KB
/
runners.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
resource "null_resource" "bastion-runner" {
depends_on = [null_resource.cockroach-runner]
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/yulu_assignment.pem")}"
host = "${aws_eip.bastion_eip.public_ip}"
}
provisioner "file" {
source = "download_binary.sh"
destination = "/home/ubuntu/download_binary.sh"
}
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install nethogs",
"mkdir -p logs",
"chmod 755 cockroach",
"[ $(stat --format=%s cockroach) -ne 0 ] || sudo bash download_binary.sh cockroach/cockroach ${var.cockroach_sha}",
"cockroach init --insecure --host=${aws_instance.roach_instance[0].private_ip}"
]
}
}
resource "null_resource" "cockroach-runner" {
count = "${var.num_of_instances}"
depends_on = [aws_eip.bastion_eip]
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/yulu_assignment.pem")}"
host = "${element(aws_instance.roach_instance.*.private_ip, count.index)}"
bastion_host = "${aws_eip.bastion_eip.public_ip}"
bastion_user = "ubuntu"
bastion_private_key = "${file("~/.ssh/yulu_assignment.pem")}"
}
provisioner "file" {
source = "download_binary.sh"
destination = "/home/ubuntu/download_binary.sh"
}
provisioner "file" {
# If no binary is specified, we'll copy /dev/null (always 0 bytes) to the
# instance. The "remote-exec" block will then overwrite that. There's no
# such thing as conditional file copying in Terraform, so we fake it.
source = "${coalesce(var.cockroach_binary, "/dev/null")}"
destination = "/home/ubuntu/cockroach"
}
# Launch CockroachDB.
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt install -y chrony",
"sudo sed -i '1i server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4' /etc/chrony/chrony.conf",
"sudo /etc/init.d/chrony restart",
"sudo apt-get -y install nethogs",
"mkdir -p logs",
"chmod 755 cockroach",
"[ $(stat --format=%s cockroach) -ne 0 ] || sudo bash download_binary.sh cockroach/cockroach ${var.cockroach_sha}",
"cockroach start --insecure --advertise-addr=${element(aws_instance.roach_instance.*.private_ip, count.index)} --join=${join(",", aws_instance.roach_instance.*.private_ip)} --cache=.25 --max-sql-memory=.25 --background"
]
}
}