dmacvicar / terraform-provider-libvirt

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

Network is not started if inactive #1095

Open dansrogers opened 2 weeks ago

dansrogers commented 2 weeks ago

System Information

Linux distribution

Ubuntu 24.04 LTS

Terraform version

$ terraform -v
Terraform v1.9.5-dev
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.7.6

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

Provider and libvirt versions

registry.terraform.io/dmacvicar/libvirt v0.7.6

libvirt-daemon                                 10.0.0-2ubuntu8.3                        amd64        Virtualization daemon

Description of Issue/Question

Network is not started if it is down. If network is not set to autostart on boot, then after a restart it will be inactive. Terraform apply will not activate the network, and thus VMs that depend on that network will fail to start.

Setup

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

# Configure the Libvirt provider
provider "libvirt" {
  uri = "qemu:///system"
}

resource "libvirt_network" "cluster" {
  name = "cluster"
  mode = "route"
  addresses = ["10.0.1.0/24"]
  dhcp {
    enabled = true
  }
}

Steps to Reproduce Issue

$ terraform apply
$ virsh net-destroy cluster
$ terraform apply
# note that terraform doesn't bring up the network.  It must be manually started with virsh net-start cluster

If you include a domain definition, you'll get an error similar to the following if the cluster is not active:

╷
│ Error: error creating libvirt domain: Requested operation is not valid: network 'cluster' is not active
│ 
│   with module.worker.libvirt_domain.devlab_cluster,
│   on modules/libvirt_talos_host/main.tf line 27, in resource "libvirt_domain" "devlab_cluster":
│   27: resource "libvirt_domain" "devlab_cluster" {
│ 
╵

Additional information:

Do you have SELinux or Apparmor/Firewall enabled? Some special configuration?

no

scabala commented 1 week ago

I have encountered it as well. I believe this is just a limitation of current implementation and probably needs to be addressed.