-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode_worker.tf
96 lines (82 loc) · 3.22 KB
/
node_worker.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
resource "openstack_compute_instance_v2" "swarm_worker" {
count = "${var.num_workers}"
name = "${format("${var.cluster_name}-%02d", count.index + 1)}"
image_name = "${var.image}"
flavor_name = "${var.flavor_worker}"
key_pair = "${openstack_compute_keypair_v2.ssh_key.name}"
network {
port = "${element(openstack_networking_port_v2.ext_port.*.id, count.index)}"
}
network {
port = "${element(openstack_networking_port_v2.mgmt_port.*.id, count.index)}"
}
}
resource "openstack_blockstorage_volume_v2" "worker-docker-vol" {
count = "${var.num_workers}"
name = "${format("${var.cluster_name}-%02d-docker-vol", count.index + 1)}"
description = "Shared volume for Docker image cache"
size = "${var.docker_volume_size}"
}
resource "openstack_compute_volume_attach_v2" "worker-docker-vol" {
count = "${var.num_workers}"
depends_on = ["openstack_compute_instance_v2.swarm_worker", "openstack_blockstorage_volume_v2.worker-docker-vol"]
instance_id = "${element(openstack_compute_instance_v2.swarm_worker.*.id, count.index)}"
volume_id = "${element(openstack_blockstorage_volume_v2.worker-docker-vol.*.id, count.index)}"
}
resource "null_resource" "provision_worker" {
count = "${var.num_workers}"
depends_on = ["openstack_networking_floatingip_v2.swarm_worker_ip", "null_resource.provision_manager"]
connection {
user = "${var.ssh_user_name}"
private_key = "${file("${var.ssh_key_file}")}"
host = "${element(openstack_networking_floatingip_v2.swarm_worker_ip.*.address, count.index)}"
}
provisioner "remote-exec" {
inline = ["sudo hostnamectl set-hostname ${element(openstack_compute_instance_v2.swarm_worker.*.name, count.index)}"]
}
provisioner "remote-exec" {
inline = [
"mkdir -p /home/ubuntu/wholetale/",
"mkdir -p /home/ubuntu/.ssh/",
]
}
provisioner "file" {
source = "scripts/fs-init.sh"
destination = "/home/ubuntu/wholetale/fs-init.sh"
}
provisioner "file" {
source = "scripts/pre-setup-all.sh"
destination = "/home/ubuntu/wholetale/pre-setup-all.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /home/ubuntu/wholetale/pre-setup-all.sh",
"chmod +x /home/ubuntu/wholetale/fs-init.sh",
"sudo /home/ubuntu/wholetale/fs-init.sh -v -d ${element(openstack_compute_volume_attach_v2.worker-docker-vol.*.device, count.index)} -m /var/lib/docker",
"/home/ubuntu/wholetale/pre-setup-all.sh"
]
}
provisioner "remote-exec" {
inline = [
"docker swarm join --token ${data.external.swarm_join_token.result.worker} ${openstack_compute_instance_v2.swarm_manager.access_ip_v4}"
]
}
}
resource "null_resource" "worker_nfs_mounts" {
depends_on = ["null_resource.provision_fileserver"]
connection {
user = "${var.ssh_user_name}"
private_key = "${file("${var.ssh_key_file}")}"
host = "${element(openstack_networking_floatingip_v2.swarm_worker_ip.*.address, count.index)}"
}
provisioner "file" {
source = "scripts/nfs-init.sh"
destination = "/home/ubuntu/wholetale/nfs-init.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /home/ubuntu/wholetale/nfs-init.sh",
"sudo /home/ubuntu/wholetale/nfs-init.sh ${openstack_compute_instance_v2.fileserver.access_ip_v4}"
]
}
}