Terraform-provider-libvirt: Can not assign address to interface connected to isolated network

Created on 5 Dec 2018  路  9Comments  路  Source: dmacvicar/terraform-provider-libvirt

Version Reports:

Distro version of host:

Fedora 29

Terraform Version Report

Terraform v0.11.10

Provider and libvirt versions

terraform-provider-libvirt -version
./terraform-provider-libvirt was not built correctly
Compiled against library: libvirt 4.7.0
Using library: libvirt 4.7.0
Running hypervisor: QEMU 3.0.0
Running against daemon: 4.7.0

If that gives you "was not built correctly", get the Git commit hash from your local provider repository:

git describe --always --abbrev=40 --dirty

2ad0228349b2d3b487a2ada25d1a0eb40d73b7d1

Description of Issue/Question

When creating new isolated network of type 'none' and assigning interface to it with static address, this address is not assigned to interface.

Setup

resource "libvirt_network" "net-01" {
  name = "kube-net"
  mode = "none"
  addresses = ["10.0.1.0/24"]
  dhcp {
    enabled = false
  }
}

resource "libvirt_domain" "node-01" {
  name = "node-01"
  memory = "512"
  vcpu = 2

  network_interface {
    network_id = "${libvirt_network.net-01.id}"
    addresses = ["10.0.1.3"]
  }
bug enhancement

Most helpful comment

moving this feature in project plaining. We might need to investigate on it after 0.60 release

All 9 comments

@grzeniek you will have more infos on this issue on this comment : https://github.com/dmacvicar/terraform-provider-libvirt/issues/441#issuecomment-442960947 hope it helps! :sunflower:

Hi, thanks for info.

As I understood enabling dhcp on network net-01 should fix my problem? So I've tried this (enabling dhcp on net-01) but I couldn't get static assigned ip address on interface, it got assigned from dhcp server.

@grzeniek May be I am missing something, but, how would configuring a static IP address from outside the VM, without assistance of the operating system network configuration, and without DHCP work?

@grzeniek for fixed ip addresses you would need the feature of defining static leases via MAC addresses, there is work beeing done garding this in PR #477

https://github.com/dmacvicar/terraform-provider-libvirt/pull/477

I thought it is possible to assign static address through 'addresses' option in network_interface definition. Now I'm doing this through cloud-init.

@MalloZup As far as I understood from the last converstation, static IP assignment is not still available for private virtual networks, right? I'm not talking about dhcp, just assign an address the the desired network interface for this domain.

As vagrant does for example (check static ip):
https://www.vagrantup.com/docs/networking/private_network.html

moving this feature in project plaining. We might need to investigate on it after 0.60 release

What came of this problem? I'm facing the same issue on following environment.

  • OS: RHEL8
  • Terraform: v0.12.18
  • Provider: terraform-provider-libvirt-0.6.0

https://github.com/dmacvicar/terraform-provider-libvirt/blob/v0.6.2/libvirt/network_def.go#L13-L20

func HasDHCP(net libvirtxml.Network) bool {
  if net.Forward != nil {
    if net.Forward.Mode == "nat" || net.Forward.Mode == "route" || net.Forward.Mode == "" {
      return true
    }
  }
  return false
}

In isolated network, Forward is nil.
But it is possible to have a DHCP server.

Because of this, it is Can not assign fixed address by DHCP when mode = "none".

I think following fixes are needed.

 func HasDHCP(net libvirtxml.Network) bool {
   if net.Forward != nil {
     if net.Forward.Mode == "nat" || net.Forward.Mode == "route" || net.Forward.Mode == "" {
       return true
     }
+  } else {
+    // isolated network
+    return true
   }
   return false
 }
Was this page helpful?
0 / 5 - 0 ratings