-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprovisioners.tf
126 lines (122 loc) · 4.98 KB
/
provisioners.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
/*
* Cassandra provisioners
*/
resource "random_id" "backup-hour" {
keepers = {
seed_eni_ids = "${join(",", aws_instance.seeds.*.id)}"
seed_data_ids = "${join(",", aws_volume_attachment.seed-data-attach.*.id)}"
seed_commit_ids = "${join(",", aws_volume_attachment.seed-commitlog-attach.*.id)}"
node_data_ids = "${join(",", aws_volume_attachment.nonseed-data-attach.*.id)}"
node_commit_ids = "${join(",", aws_volume_attachment.nonseed-commitlog-attach.*.id)}"
}
byte_length = 2
}
resource "random_id" "backup-minute" {
keepers = {
seed_eni_ids = "${join(",", aws_instance.seeds.*.id)}"
seed_data_ids = "${join(",", aws_volume_attachment.seed-data-attach.*.id)}"
seed_commit_ids = "${join(",", aws_volume_attachment.seed-commitlog-attach.*.id)}"
node_data_ids = "${join(",", aws_volume_attachment.nonseed-data-attach.*.id)}"
node_commit_ids = "${join(",", aws_volume_attachment.nonseed-commitlog-attach.*.id)}"
}
byte_length = 2
}
resource "null_resource" "seed-nodes" {
count = "${aws_instance.seeds.count}"
triggers {
data_id = "${element(aws_volume_attachment.seed-data-attach.*.id, count.index)}"
commitlog_id = "${element(aws_volume_attachment.seed-commitlog-attach.*.id, count.index)}"
seed_ip_id = "${element(aws_instance.seeds.*.id, count.index)}"
}
connection {
host = "${element(aws_instance.seeds.*.private_ip, count.index)}"
user = "${var.user}"
private_key = "${file(var.private_key)}"
bastion_host = "${var.bastion_ip}"
bastion_user = "${var.bastion_user}"
bastion_private_key = "${file(var.bastion_private_key)}"
}
provisioner "file" {
content = "${data.template_file.datastax-repo.rendered}"
destination = "/tmp/datastax.repo"
}
provisioner "file" {
content = "${data.template_file.setup-cassandra.rendered}"
destination = "/tmp/setup-cassandra.sh"
}
provisioner "file" {
content = "${data.template_file.cassandra-status.rendered}"
destination = "/tmp/cassandra-status.sh"
}
provisioner "remote-exec" {
inline = [
"sudo mv /tmp/datastax.repo /etc/yum.repos.d/",
"sudo chown root:root /etc/yum.repos.d/datastax.repo",
"chmod +x /tmp/setup-cassandra.sh",
"sudo /tmp/setup-cassandra.sh",
"rm /tmp/setup-cassandra.sh",
"sudo yum install -y git",
"git clone ${var.backup_script_url} /tmp/ebs-backup",
"cd /tmp/ebs-backup",
"sudo python setup.py install",
"cd /tmp",
"sudo rm -rf /tmp/ebs-backup",
"echo '${random_id.backup-minute.dec % 60} ${random_id.backup-hour.dec % 24} * * * ebs-backup -l /var/log/cassandra/backup.log -r ${var.backup_retention}' > /tmp/crontab",
"sudo mv /tmp/cassandra-status.sh ${var.data_root}/cassandra-status.sh",
"sudo chown cassandra:cassandra ${var.data_root}/cassandra-status.sh",
"sudo chmod +x ${var.data_root}/cassandra-status.sh",
"echo '* * * * * ${var.data_root}/cassandra-status.sh' >> /tmp/crontab",
"sudo crontab -u cassandra /tmp/crontab",
"rm /tmp/crontab"
]
}
}
resource "null_resource" "nodes" {
count = "${aws_instance.nodes.count}"
triggers {
data_id = "${element(aws_volume_attachment.nonseed-data-attach.*.id, count.index)}"
commitlog_id = "${element(aws_volume_attachment.nonseed-commitlog-attach.*.id, count.index)}"
}
connection {
host = "${element(aws_instance.nodes.*.private_ip, count.index)}"
user = "${var.user}"
private_key = "${file(var.private_key)}"
bastion_host = "${var.bastion_ip}"
bastion_user = "${var.bastion_user}"
bastion_private_key = "${file(var.bastion_private_key)}"
}
provisioner "file" {
content = "${data.template_file.datastax-repo.rendered}"
destination = "/tmp/datastax.repo"
}
provisioner "file" {
content = "${data.template_file.setup-cassandra.rendered}"
destination = "/tmp/setup-cassandra.sh"
}
provisioner "file" {
content = "${data.template_file.cassandra-status.rendered}"
destination = "/tmp/cassandra-status.sh"
}
provisioner "remote-exec" {
inline = [
"sudo mv /tmp/datastax.repo /etc/yum.repos.d/",
"sudo chown root:root /etc/yum.repos.d/datastax.repo",
"chmod +x /tmp/setup-cassandra.sh",
"sudo /tmp/setup-cassandra.sh",
"rm /tmp/setup-cassandra.sh",
"sudo yum install -y git",
"git clone ${var.backup_script_url} /tmp/ebs-backup",
"cd /tmp/ebs-backup",
"sudo python setup.py install",
"cd /tmp",
"sudo rm -rf /tmp/ebs-backup",
"echo '${random_id.backup-minute.dec % 60} ${random_id.backup-hour.dec % 24} * * * ebs-backup -l /var/log/cassandra/backup.log -r ${var.backup_retention}' > /tmp/crontab",
"sudo mv /tmp/cassandra-status.sh ${var.data_root}/cassandra-status.sh",
"sudo chown cassandra:cassandra ${var.data_root}/cassandra-status.sh",
"sudo chmod +x ${var.data_root}/cassandra-status.sh",
"echo '* * * * * ${var.data_root}/cassandra-status.sh' >> /tmp/crontab",
"sudo crontab -u cassandra /tmp/crontab",
"rm /tmp/crontab"
]
}
}