-
Notifications
You must be signed in to change notification settings - Fork 2
/
load.tf
146 lines (122 loc) · 3.8 KB
/
load.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Various examples that can be run against a cockroach cluster in GCE.
# A cockroach cluster should be created first by following the steps in README.md.
# To enable an example, change the number of instances on the command line. eg:
# terraform apply <flags for cockroach cluster> --var=block_writer_instances=1
# Number of instances for the block writer example. Set to 1 to enable the example.
# The block writer example does not support multiple instances. Expect badness if
# set greater than 1.
variable "block_writer_instances" {
default = 1
}
output "block_writer_ips" {
value = "${join(",", google_compute_instance.block_writer.*.network_interface.0.access_config.0.assigned_nat_ip)}"
}
output "block_writer_instances" {
value = "${join(",", google_compute_instance.block_writer.*.name)}"
}
resource "google_compute_instance" "block_writer" {
count = "${var.block_writer_instances}"
name = "block-writer-${count.index}"
machine_type = "${var.gce_machine_type}"
zone = "${var.gce_zone}"
tags = ["cockroach"]
disk {
image = "${var.gce_image}"
}
network_interface {
network = "default"
access_config {
# Ephemeral
}
}
metadata {
sshKeys = "ubuntu:${file("~/.ssh/${var.key_name}.pub")}"
}
connection {
user = "ubuntu"
key_file = "~/.ssh/${var.key_name}"
}
service_account {
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
}
provisioner "file" {
source = "download_binary.sh"
destination = "/home/ubuntu/download_binary.sh"
}
# This writes the filled-in supervisor template. It would be nice if we could
# use rendered templates in the file provisioner.
provisioner "remote-exec" {
inline = <<FILE
echo '${template_file.supervisor.0.rendered}' > supervisor.conf
FILE
}
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install supervisor",
"sudo service supervisor stop",
"bash download_binary.sh examples-go/block_writer ${var.block_writer_sha}",
"mkdir -p logs",
"if [ ! -e supervisor.pid ]; then supervisord -c supervisor.conf; fi",
"supervisorctl -c supervisor.conf start block_writer",
]
}
}
variable "photos_instances" {
# don't set to > 1 for now
default = 1
}
output "photos_ips" {
value = "${join(",", google_compute_instance.photos.*.network_interface.0.access_config.0.assigned_nat_ip)}"
}
output "photos_instances" {
value = "${join(",", google_compute_instance.photos.*.name)}"
}
resource "google_compute_instance" "photos" {
count = "${var.photos_instances}"
name = "photos-${count.index}"
machine_type = "${var.gce_machine_type}"
zone = "${var.gce_zone}"
tags = ["cockroach"]
disk {
image = "${var.gce_image}"
}
network_interface {
network = "default"
access_config {
# Ephemeral
}
}
metadata {
sshKeys = "ubuntu:${file("~/.ssh/${var.key_name}.pub")}"
}
connection {
user = "ubuntu"
key_file = "~/.ssh/${var.key_name}"
}
service_account {
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
}
provisioner "file" {
source = "download_binary.sh"
destination = "/home/ubuntu/download_binary.sh"
}
# This writes the filled-in supervisor template. It would be nice if we could
# use rendered templates in the file provisioner.
provisioner "remote-exec" {
inline = <<FILE
echo '${template_file.supervisor.0.rendered}' > supervisor.conf
FILE
}
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install supervisor",
"sudo service supervisor stop",
"bash download_binary.sh examples-go/photos ${var.photos_sha}",
"mkdir -p logs",
"if [ ! -e supervisor.pid ]; then supervisord -c supervisor.conf; fi",
"supervisorctl -c supervisor.conf start photos",
]
}
}