I have a requirement to deploy small networks of roughly 30 VMs that are used for training, and then destroy them after about a week. I use Terraform to automate the deployment of these networks. This deployment is happening on-prem on ESXi.
I use Vyos for all the routers. However, I’m having an issue deploying Vyos using Terraform. I can get the Vyos VM to deploy, but I cannot get the network adapters to accept any configurations from Terraform. When I add any scripts to configure the interfaces, Terraform fails. What ends up happening is the VM deploys, it contains the correct number of network interfaces (set using Terraform), but none of the interfaces have an IP address. This is the point where I’m stuck.
To get past the Terraform issue I use Ansible to configure the Vyos routers, but in order for Ansible to connect to the router it needs an IP address. So to get Ansible to work I need to console into each router in order to set the IP address manually. This works, but these extra steps really hinders the automation process. Sometimes I’m deploying four or more routers, and having to console into each router to configure it is taking a lot of time, and introduces errors.
I’ve tried using the ‘extra_config’ module of Terraform in order to try and pass configurations to Vyos during the deployment phase, but I cannot get it to work.
Here is the minimal Terraform code I’m using to deploy the VM:
# DEPLOY Core-Router Router
resource "vsphere_virtual_machine" "RTR-Core-01" {
name = "${var.RGE_PREFIX}-RTR-Core-01"
folder = "${vsphere_folder.BlueSpace.path}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = 2
memory = 4096
guest_id = "${data.vsphere_virtual_machine.Core-Router-01.guest_id}"
scsi_type = "${data.vsphere_virtual_machine.Core-Router-01.scsi_type}"
firmware = "efi"
wait_for_guest_net_timeout = -1
network_interface {
network_id = "${data.vsphere_network.VLAN-0.id}"
adapter_type = "vmxnet3"
}
network_interface {
network_id = "${data.vsphere_network.VLAN-0.id}"
adapter_type = "vmxnet3"
}
disk {
label = "disk0"
size = "${data.vsphere_virtual_machine.Core-Router-01.disks.0.size}"
eagerly_scrub = "${data.vsphere_virtual_machine.Core-Router-01.disks.0.eagerly_scrub}"
thin_provisioned = "${data.vsphere_virtual_machine.Core-Router-01.disks.0.thin_provisioned}"
}
extra_config = {
"guestinfo.userdata" = base64gzip(file("vyos.commands.yaml"))
"guestinfo.userdata.encoding" = "gzip+base64"
}
clone {
template_uuid = "${data.vsphere_virtual_machine.Core-Router-01.id}"
}
}
and here is the vyos.commands.yaml file:
write_files:
- path: /opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script
owner: vyos:vyos
permissions: '0775'
content: |
#!/bin/bash
set interfaces eth0 address '1.1.1.1/24'
Once the Vyos VM boots, I look in/opt/vyatta/etc/config/scripts/vyos-postconfig-bootup.script but the file is untouched.
If anyone could show me the correct way to implement the ‘write_files’ feature of Vyos using Terraform I’m sure I’d be able to completely automate the deployment process.
Kelly