Changing the interface IP on Vyos in an inline script causes timeout

We have a shell provisioner for a Vyos installation that looks like:

    provisioner "shell" {
      inline = [
        "source /opt/vyatta/etc/functions/script-template",
        "configure",
#        "load /tmp/config.boot",
#        "commit"
        "delete interface ethernet eth0 address dhcp",
        "set interface ethernet eth0 address 10.0.0.1/30",
        "commit",
        "save",
        "delete interface ethernet eth0 hw-id",
        "commit",
        "save",
        "set interface ethernet eth1 address 192.168.1.1/24",
        "commit",
        "save",
        "delete interface ethernet eth1 hw-id",
        "commit",
        "save",
      ]
      inline_shebang    = "/bin/vbash"
      expect_disconnect = true
      timeout = "0h0m30s"
    }

eth0 is previously getting an IP from dhcp, and we see it connects fine with the provisioner, uploads the script, and execution starts. If we remove the timeout it will hang forever, and if we don’t change eth0 it will complete just fine.

==> vsphere-iso.vyos_vsphere_iso: Creating VM...
==> vsphere-iso.vyos_vsphere_iso: Customizing hardware...
==> vsphere-iso.vyos_vsphere_iso: Mounting ISO images...
==> vsphere-iso.vyos_vsphere_iso: Adding configuration parameters...
==> vsphere-iso.vyos_vsphere_iso: Set boot order...
==> vsphere-iso.vyos_vsphere_iso: Power on VM...
==> vsphere-iso.vyos_vsphere_iso: Waiting 5s for boot...
==> vsphere-iso.vyos_vsphere_iso: Typing boot command...
==> vsphere-iso.vyos_vsphere_iso: Waiting for IP...
==> vsphere-iso.vyos_vsphere_iso: IP address: 192.168.100.9
==> vsphere-iso.vyos_vsphere_iso: Using SSH communicator to connect: 192.168.100.9
==> vsphere-iso.vyos_vsphere_iso: Waiting for SSH to become available...
==> vsphere-iso.vyos_vsphere_iso: Connected to SSH!
==> vsphere-iso.vyos_vsphere_iso: Setting a 30s timeout for the next provisioner...
==> vsphere-iso.vyos_vsphere_iso: Provisioning with shell script: /tmp/packer-shell1754382940

Is there a way to tell the provisioner it can disconnect or otherwise get around this issue?

Fails with:

==> vsphere-iso.vyos_vsphere_iso: Cancelling provisioner after a timeout...
==> vsphere-iso.vyos_vsphere_iso: Provisioning step had errors: Running the cleanup provisioner, if present...
==> vsphere-iso.vyos_vsphere_iso: Power off VM...
==> vsphere-iso.vyos_vsphere_iso: Destroying VM...
Build 'vsphere-iso.vyos_vsphere_iso' errored after 4 minutes 25 seconds: context canceled

The solution for Vyos was to continue using the inline shell but keep a connection open. We keep the connection open by configuring an additional interface with DHCP via the boot command. This should be the last interface for the device.

For the core_router the DHCP interface is eth2 and we configure eth0 and eth1 for different things needed in the lab (connections to other routers). Then, when Terraform deploys the router, it configures interface in order per their docs:

Network interfaces are managed by adding an instance of the network_interface block.

Interfaces are assigned to devices in the specific order they are declared. This has different implications for different operating systems.

We only create interfaces for eth0 and eth1, so when Vyos boots, it discards eth2 confgurations.