Hello,
I am experimenting with a qemu builder setup.
I would like to set the host port forwarding manually. This would allow me to also run external scripts (ansible, terraform, chef …) against the running instance. But for this to work I need to expose the port.
Maybe there is a simpler way, but what I tried to do is:
qemu_args = [["-nic", "user,model=virtio,hostfwd=tcp::${build.Port}-:22"]]
The part of interrest is:
hostfwd=tcp::${build.Port}-:22
According to the documentation, this should be possible for provisioners: Contextual Variables - HCL Configuration Language | Packer | HashiCorp Developer
But I need to know this during build time.
From the logs I can also see that the lookup and assignment of the port happens before the actual run step. Therefore the port would be known at that time, but I could not find any way to access it.
I guess these are some relevant areas:
- packer-plugin-qemu/ssh.go at main · hashicorp/packer-plugin-qemu · GitHub
- packer-plugin-qemu/step_port_forward.go at main · hashicorp/packer-plugin-qemu · GitHub
- Communicators - SSH | Packer | HashiCorp Developer
Thanks