-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-esx-host-networking.tf
63 lines (56 loc) · 2.18 KB
/
08-esx-host-networking.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
resource "null_resource" "copy_update_uplinks" {
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/${local.ssh_key_name}")
host = packet_device.router.access_public_ipv4
}
provisioner "file" {
content = file("templates/update_uplinks.py")
destination = "/root/update_uplinks.py"
}
}
data "template_file" "esx_host_networking" {
template = file("templates/esx_host_networking.py")
vars = {
private_subnets = jsonencode(var.private_subnets)
private_vlans = jsonencode(packet_vlan.private_vlans.*.vxlan)
public_subnets = jsonencode(var.public_subnets)
public_vlans = jsonencode(packet_vlan.public_vlans.*.vxlan)
public_cidrs = jsonencode(packet_reserved_ip_block.ip_blocks.*.cidr_notation)
domain_name = var.domain_name
packet_token = var.auth_token
}
}
resource "null_resource" "esx_network_prereqs" {
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/${local.ssh_key_name}")
host = packet_device.router.access_public_ipv4
}
provisioner "file" {
content = data.template_file.esx_host_networking.rendered
destination = "/root/esx_host_networking.py"
}
}
resource "null_resource" "apply_esx_network_config" {
count = length(packet_device.esxi_hosts)
depends_on = [
packet_port_vlan_attachment.esxi_priv_vlan_attach,
packet_port_vlan_attachment.esxi_pub_vlan_attach,
null_resource.esx_network_prereqs,
null_resource.copy_update_uplinks,
null_resource.install_vpn_server
]
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/${local.ssh_key_name}")
host = packet_device.router.access_public_ipv4
}
provisioner "remote-exec" {
inline = ["python3 /root/esx_host_networking.py --host '${element(packet_device.esxi_hosts.*.access_public_ipv4, count.index)}' --user root --pass '${element(packet_device.esxi_hosts.*.root_password, count.index)}' --id '${element(packet_device.esxi_hosts.*.id, count.index)}' --index ${count.index} --ipRes ${element(packet_reserved_ip_block.esx_ip_blocks.*.id, count.index)}"]
on_failure = continue
}
}