Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I specify virtual network device? #1075

Open
alexeyyakimovich opened this issue Feb 27, 2024 · 2 comments
Open

How can I specify virtual network device? #1075

alexeyyakimovich opened this issue Feb 27, 2024 · 2 comments

Comments

@alexeyyakimovich
Copy link

System Information

Linux distribution

Ubuntu 22.04

Terraform version

OpenTofu v1.6.1
on darwin_arm64

Provider and libvirt versions

provider registry.opentofu.org/dmacvicar/libvirt v0.7.6
libvirtd (libvirt) 8.0.0

Description of Issue/Question

I want to bind virtual network to specific host interface, but i can't find the way to do it.
I don't know if this feature is missing or it's just a documentation issue.

Setup

terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
      version = "0.7.6"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://..."
}


resource "libvirt_network" "services-network" {
  name = "office-services"
  mode = "route"
  domain = "services.office.internal"
  addresses = ["192.168.2.0/28"]
  bridge = "office-services"
  autostart = true
  
  dhcp {
    enabled = true
  }
  
  dns {
    enabled = true
    local_only = true

    forwarders {
        address = "172.16.0.9"
        domain = "office.internal"
    }
  }
}

Steps to Reproduce Issue

This setup will generate the following network xml:

<network>
  <name>office-services</name>
  <uuid>553965c9-578c-4d58-abbf-e2fab9107430</uuid>
  <forward mode='route'/>
  <bridge name='office-services' stp='on' delay='0'/>
  <mac address='52:54:00:2d:74:e3'/>
  <domain name='services.office.internal' localOnly='yes'/>
  <dns enable='yes'>
    <forwarder domain='office.internal' addr='172.16.0.9'/>
  </dns>
  <ip family='ipv4' address='192.168.2.1' prefix='28'>
    <dhcp>
      <range start='192.168.2.2' end='192.168.2.14'/>
      <host mac='02:00:00:00:00:01' name='reverse' ip='192.168.2.2'/>
    </dhcp>
  </ip>
</network>

I've edited it manually to define dev attribute of forward node. After saving network xml becomes this way:

<network>
  <name>office-services</name>
  <uuid>553965c9-578c-4d58-abbf-e2fab9107430</uuid>
  <forward dev='office' mode='route'>
    <interface dev='office'/>
  </forward>
  <bridge name='office-services' stp='on' delay='0'/>
  <mac address='52:54:00:2d:74:e3'/>
  <domain name='services.office.internal' localOnly='yes'/>
  <dns enable='yes'>
    <forwarder domain='office.internal' addr='172.16.0.9'/>
  </dns>
  <ip family='ipv4' address='192.168.2.1' prefix='28'>
    <dhcp>
      <range start='192.168.2.2' end='192.168.2.14'/>
      <host mac='02:00:00:00:00:01' name='reverse' ip='192.168.2.2'/>
    </dhcp>
  </ip>
</network>

Is it possible to achieve this result with provider?

@scabala
Copy link
Contributor

scabala commented Sep 2, 2024

Hello,
does specifying device work with pure libvirt?

And out curiosity, what are you trying to achieve?

@alexeyyakimovich
Copy link
Author

alexeyyakimovich commented Sep 19, 2024

Hello,
yes, it works with pure libvirt )

I want to pass nic port direct to vm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants