-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
74 lines (68 loc) · 2 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
# Build the deployment.xml file
resource "xml_file" deployment {
filename = "/Users/seetasomagani/deployment.xml"
elements = var.deployment_elements
}
# Provision the VoltDB host(s)
resource "aws_instance" volt {
count = var.node_count
instance_type = var.instance_type
availability_zone = var.availability_zone
ami = var.ami
key_name = var.key_name
provisioner "file" {
source = "${xml_file.deployment.filename}"
destination = "/home/ubuntu/deployment.xml"
connection {
host = self.public_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.key_path)
}
}
provisioner "file" {
source = "${path.module}/start-volt-cluster.sh"
destination = "/home/ubuntu/start-volt-cluster.sh"
connection {
host = self.public_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.key_path)
}
}
}
resource "null_resource" "copy_license" {
count = var.license_path == "" ? 0 : var.node_count
provisioner "file" {
source = var.license_path
destination = "/opt/voltdb/voltdb/license.xml"
connection {
host = element(aws_instance.volt.*.public_ip, count.index)
type = "ssh"
user = var.ssh_user
private_key = file(var.key_path)
}
}
depends_on = ["aws_instance.volt"]
}
locals {
ips = join(",", aws_instance.volt.*.private_ip)
}
resource "null_resource" "start-volt-cluster" {
count = var.node_count
provisioner "remote-exec" {
inline = [
"chmod +x /home/ubuntu/start-volt-cluster.sh",
"/home/ubuntu/start-volt-cluster.sh ${var.node_count} ${local.ips} > startup.log",
# Without a sleep, process gets killed before it even starts
"sleep 5"
]
connection {
host = element(aws_instance.volt.*.public_ip, count.index)
type = "ssh"
user = var.ssh_user
private_key = file(var.key_path)
}
}
depends_on = ["null_resource.copy_license"]
}