-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory.tf.gomplate
47 lines (41 loc) · 2.41 KB
/
inventory.tf.gomplate
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
// when bastion_pool_count > 0 the instances won't have public_dns
// don't add ansible_host: to the inventory
locals {
inventory_format_with_ansible_host = " %s:\n ansible_host: %s\n node_pool: %s"
inventory_format = " %s:\n%s node_pool: %s"
inventory_control_plane_format_with_ansible_host = " %s:\n ansible_host: %s"
inventory_control_plane_format = " %s:%s"
bastion_vars_format = " %s"
bastion_hosts_format = " %s:\n ansible_host: %s"
}
// TODO
// Need to set order until https://github.com/ansible/ansible/issues/34861 is fixed to preserve order across runs
resource "local_file" "ansible_inventory" {
filename = "${var.inventory_path}"
provisioner "local-exec" {
command = "chmod 644 ${var.inventory_path}"
}
content = <<EOF
all:
vars:
version: "${var.inventory_version}"
order: sorted
control_plane_endpoint: "${aws_elb.konvoy_control_plane.*.dns_name[0]}:6443"
ansible_user: "${var.ssh_user}"
ansible_port: 22
${chomp(join("\n", compact(list(
var.ssh_private_key_file == "" ? "" : " ansible_ssh_private_key_file: \"${var.ssh_private_key_file}\"",
))))}
control-plane:
hosts:
${join("\n", formatlist((var.bastion_pool_count > 0) || (var.create_vpc_internet_gateway == "0") ? local.inventory_control_plane_format : local.inventory_control_plane_format_with_ansible_host, aws_instance.control_plane.*.private_ip, aws_instance.control_plane.*.public_dns))}
node:
${chomp(join("\n", list(
{{ range $index := (ds "config").pools }}(var.worker_pool{{$index}}_count > 0) || {{end}}(false) ? " hosts:" : "",
{{ range $index := (ds "config").pools }}join("\n", formatlist((var.bastion_pool_count > 0) || (var.create_vpc_internet_gateway == "0") ? local.inventory_format : local.inventory_format_with_ansible_host, aws_instance.worker_pool{{$index}}.*.private_ip, aws_instance.worker_pool{{$index}}.*.public_dns, var.worker_pool{{$index}}_name)),
{{end}})))}
bastion:
${var.bastion_pool_count == 0 ? "" : join("\n", concat(list(" hosts:"), formatlist(local.bastion_hosts_format, aws_instance.bastion.*.private_ip, aws_instance.bastion.*.public_dns)))}
${var.bastion_pool_count == 0 ? "" : join("\n", concat(list(" vars:"), formatlist(local.bastion_vars_format, compact(list("ansible_user: \"${var.ssh_user}\"", "ansible_port: 22"))))) }
EOF
}