-
Notifications
You must be signed in to change notification settings - Fork 24
/
etc_hosts.tf
44 lines (39 loc) · 1.98 KB
/
etc_hosts.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
# Bash command to populate /etc/hosts file on each instances
resource "null_resource" "provision_node_hosts_file" {
count = var.node_count
triggers = {
rerun = random_id.cluster_token.hex
}
connection {
host = element(digitalocean_droplet.microk8s-node.*.ipv4_address, count.index)
user = "root"
type = "ssh"
private_key = file(var.digitalocean_private_key)
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"echo '${join("\n", formatlist("%v", digitalocean_droplet.microk8s-node.*.ipv4_address_private))}' | awk 'BEGIN{ print \"\\n\\n# Node members:\" }; { print $0 \" microk8s-node-${var.cluster_name}-\" NR-1}' | sudo tee -a /etc/hosts > /dev/null",
"echo '${join("\n", formatlist("%v", digitalocean_droplet.microk8s-worker-node.*.ipv4_address_private))}' | awk 'BEGIN{ print \"\\n\\n# Worker node members:\" }; { print $0 \" microk8s-worker-${var.cluster_name}-\" NR-1}' | sudo tee -a /etc/hosts > /dev/null",
]
}
}
resource "null_resource" "provision_worker_hosts_file" {
count = var.worker_node_count
triggers = {
rerun = random_id.cluster_token.hex
}
connection {
host = element(digitalocean_droplet.microk8s-worker-node.*.ipv4_address, count.index)
user = "root"
type = "ssh"
private_key = file(var.digitalocean_private_key)
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"echo '${join("\n", formatlist("%v", digitalocean_droplet.microk8s-node.*.ipv4_address_private))}' | awk 'BEGIN{ print \"\\n\\n# Node members:\" }; { print $0 \" microk8s-node-${var.cluster_name}-\" NR-1}' | sudo tee -a /etc/hosts > /dev/null",
"echo '${join("\n", formatlist("%v", digitalocean_droplet.microk8s-worker-node.*.ipv4_address_private))}' | awk 'BEGIN{ print \"\\n\\n# Worker node members:\" }; { print $0 \" microk8s-worker-${var.cluster_name}-\" NR-1}' | sudo tee -a /etc/hosts > /dev/null",
]
}
}