-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovisioner.tf
66 lines (54 loc) · 1.95 KB
/
provisioner.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
resource "null_resource" "master_init" {
count = var.swarm_master_count
triggers = {
cluster_instance_ids = digitalocean_droplet.docker_swarm_master.*.id[0]
}
connection {
host = digitalocean_droplet.docker_swarm_master.*.ipv4_address[0]
user = var.do_user
agent = true
}
provisioner "local-exec" {
command = "scripts/master.init.sh ${var.do_user} ${digitalocean_droplet.docker_swarm_master.*.ipv4_address[0]} ${digitalocean_droplet.docker_swarm_master.*.ipv4_address_private[0]}"
}
}
resource "null_resource" "worker_init" {
count = var.swarm_worker_count
triggers = {
cluster_instance_ids = digitalocean_droplet.docker_swarm_worker.*.id[count.index]
cluster_instance_ips = digitalocean_droplet.docker_swarm_worker.*.ipv4_address[count.index]
cluster_user_id = var.do_user
}
connection {
timeout = "2m"
host = "self.triggers.cluster_instance_ips"
user = "self.triggers.cluster_user_id"
agent = true
}
provisioner "remote-exec" {
when = destroy
on_failure = continue
inline = [
"timeout 120 cioctl remove"
]
}
provisioner "local-exec" {
command = "bash scripts/worker.init.sh ${var.do_user} ${digitalocean_droplet.docker_swarm_worker.*.ipv4_address[count.index]} ${digitalocean_droplet.docker_swarm_worker.*.ipv4_address_private[count.index]} ${digitalocean_droplet.docker_swarm_master.*.ipv4_address[0]}"
}
depends_on = [
digitalocean_droplet.docker_swarm_master
]
}
resource "null_resource" "master_deploy" {
triggers = {
cluster_instance_ids = null_resource.worker_init.*.id[0]
}
connection {
host = digitalocean_droplet.docker_swarm_master.*.ipv4_address[0]
user = var.do_user
agent = true
}
provisioner "local-exec" {
command = "scripts/master.start.sh ${var.do_user} ${digitalocean_droplet.docker_swarm_master.*.ipv4_address[0]} ${digitalocean_droplet.docker_swarm_master.*.ipv4_address_private[0]}"
}
}