dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

Is there a way to add Spice channels? #975

Open jerrac opened 1 year ago

jerrac commented 1 year ago

System Information

Linux distribution

Pop OS 20.04

Terraform version

Terraform v1.2.9
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.6.14
+ provider registry.terraform.io/hashicorp/template v2.2.0

Your version of Terraform is out of date! The latest version
is 1.3.0. You can update by downloading from https://www.terraform.io/downloads.html

Provider and libvirt versions

Terraform v1.2.9
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.6.14
+ provider registry.terraform.io/hashicorp/template v2.2.0

Checklist

Description of Issue/Question

I'd like to be able to add Spice Channels to my vm. Specifically to support "Auto resize vm with window", text copy/paste, and webdav file transfers between host and vm.

If a vm is meant for use involving a GUI, dynamic window resizing and copy/paste between guest and host are absolutely essential to any workflow. As far as I can tell, the libvirt way to do this is via Spice. By default virt-manager sets up the spice-vdagent channel on new VM's created via it's GUI. I'm 90% certain Vagrant does as well.

For quick file sharing, you can install spice-webdavd and use virt-viewer to share a folder on the host with the guest. That does require adding a Spice channel specifically for spice-webdavd.

My specific use case right now is setting up an easy to deploy development vm using Packer, Terraform, and Ansible. But I've been messing with VM's for years and always end up setting up spice-vdagent if I need to use the GUI.

Is there a way for me to add spice channels to the my libvirt_domain? I went through the docs as thoroughly as I could and didn't see anything that would work. I tried adding consoles, but there didn't seem to be a way to make them match the config I get when adding spice channels manually.

I did see the xml/xslt block. But its description makes me think it is meant to modify existing nodes in the machine's xml. Not for adding new nodes, right? Or can it do what I want? I'm no xml expert, so translating the one example with a nic to something else is beyond me.

Setup

N/A

Steps to Reproduce Issue

N/A


Additional information:

libvirt docs

Here's the XML from virt-manager's GUI for the spice channel for the spice-vdagent service:

<channel type="spicevmc">
  <target type="virtio" name="com.redhat.spice.0" state="disconnected"/>
  <alias name="channel1"/>
  <address type="virtio-serial" controller="0" bus="0" port="2"/>
</channel>

Here's the XML from virt-manager's GUI for the spice channel for the spice-webdavd agent:

<channel type="spiceport">
  <source channel="org.spice-space.webdav.0"/>
  <target type="virtio" name="org.spice-space.webdav.0" state="disconnected"/>
  <alias name="channel2"/>
  <address type="virtio-serial" controller="0" bus="0" port="3"/>
</channel>

Thanks in advance!

bestrocker221 commented 1 year ago

Hi, I add the spice channel via XML import.

I pushed this example file that worked, under examples/ here

xml {
    xslt = file("add_spicevmc.xsl")
  }