Skip to content

Commit

Permalink
terraform: generate hardware-data-0.json on provisioner, include sos …
Browse files Browse the repository at this point in the history
…user@host in output

Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Sep 4, 2020
1 parent 69bb79b commit 41d92cd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
32 changes: 32 additions & 0 deletions deploy/terraform/hardware_data.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "${id}",
"metadata": {
"facility": {
"facility_code": "${facility_code}",
"plan_slug": "${plan_slug}",
"plan_version_slug": ""
},
"instance": {},
"state": ""
},
"network": {
"interfaces": [
{
"dhcp": {
"arch": "x86_64",
"ip": {
"address": "${address}",
"gateway": "192.168.1.1",
"netmask": "255.255.255.248"
},
"mac": "${mac}",
"uefi": false
},
"netboot": {
"allow_pxe": true,
"allow_workflow": true
}
}
]
}
}
26 changes: 26 additions & 0 deletions deploy/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ resource "packet_port_vlan_attachment" "worker" {
port_name = "eth0"
vlan_vnid = packet_vlan.provisioning_vlan.vxlan
}

data "template_file" "worker_hardware_data" {
count = var.worker_count
template = file("${path.module}/hardware_data.tpl")
vars = {
id = packet_device.tink_worker[count.index].id
facility_code = packet_device.tink_worker[count.index].deployed_facility
plan_slug = packet_device.tink_worker[count.index].plan
address = "192.168.1.${count.index + 5}"
mac = packet_device.tink_worker[count.index].ports[1].mac
}
}

resource "null_resource" "hardware_data" {
count = var.worker_count
connection {
type = "ssh"
user = var.ssh_user
host = packet_device.tink_provisioner.network[0].address
}

provisioner "file" {
content = data.template_file.worker_hardware_data[count.index].rendered
destination = "/root/tink/deploy/hardware-data-${count.index}.json"
}
}
6 changes: 5 additions & 1 deletion deploy/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ output "provisioner_ip" {
}

output "worker_mac_addr" {
value = packet_device.tink_worker[0].ports[1].mac
value = formatlist("%s", packet_device.tink_worker[*].ports[1].mac)
}

output "worker_sos" {
value = formatlist("%s@sos.%s.packet.net", packet_device.tink_worker[*].id, packet_device.tink_worker[*].deployed_facility)
}

0 comments on commit 41d92cd

Please sign in to comment.