terraform-provider-libvirt icon indicating copy to clipboard operation
terraform-provider-libvirt copied to clipboard

terraform-provider-libvirt keeps changing network_interface

Open bjvrielink opened this issue 3 years ago • 2 comments

System Information

Linux distribution

Alpine Linux v3.13

Terraform version

Terraform v0.15.3
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.6.3
+ provider registry.terraform.io/hashicorp/aws v3.27.0
+ provider registry.terraform.io/hashicorp/dns v3.1.0
+ provider registry.terraform.io/hashicorp/local v2.1.0

Provider and libvirt versions

./terraform-provider-libvirt 076b2da9551370b622307983059515b6ff83e37d
Compiled against library: libvirt 6.10.0
Using library: libvirt 6.10.0
2021/05/16 10:34:31 virError(Code=38, Domain=7, Message='Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory')

Checklist

  • [ ] Is your issue/contribution related with enabling some setting/option exposed by libvirt that the plugin does not yet support, or requires changing/extending the provider terraform schema?

    • [ ] Make sure you explain why this option is important to you, why it should be important to everyone. Describe your use-case with detail and provide examples where possible.
    • [ ] If it is a very special case, consider using the XSLT support in the provider to tweak the definition instead of opening an issue
    • [ ] Maintainers do not have expertise in every libvirt setting, so please, describe the feature and how it is used. Link to the appropriate documentation
  • [X] Is it a bug or something that does not work as expected? Please make sure you fill the version information below:

Description of Issue/Question

Each and every time I run terraform plan or apply, terraform-provider-libvirt wants to change the network interfaces of the VM's.

Setup

resource "libvirt_network" "dmz" {
  name = "dmz"
  autostart = true
  mode = "bridge"
  bridge = "dmz"
}

resource "libvirt_domain" "this" {
  autostart = true
  name = var.host_name
  memory = var.mem_size
  vcpu = var.cpu_count
  cloudinit = libvirt_cloudinit_disk.this.id

  console {
    type        = "pty"
    target_type = "serial"
    target_port = "0"
  }

  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }

  network_interface {
    network_id = libvirt_network.dmz.id
  }

  disk {
    volume_id = libvirt_volume.this.id
  }
}

Steps to Reproduce Issue

When terraform plan runs, it wants to change the network interface:

      ~ network_interface {
          - bridge         = "dmz" -> null
          + network_id     = "5e23fbb5-0243-432e-84b0-c5cb07d4b5a8"

This change does not impact the running VM. The risk is that when you have a changed resource each and every time you run terraform plan, there will be a day that you overlook another change (on the same resource) that has impact.


Additional information:

I run terraform as a docker container (hashicorp/terraform:latest) as part of a Gitlab CI pipeline. The docker host has SELinux, but not in a way that should affect this issue.

bjvrielink avatar May 16 '21 10:05 bjvrielink

@bjvrielink Did you ever find a workaround for this?

marshallford avatar Mar 31 '22 00:03 marshallford

I worked around this by changing how the domain connects to the network. What I had was:

resource "libvirt_domain" "this" {
   network_interface {
     network_id = var.network_id
   }
}

I refactored my code into:

resource "libvirt_domain" "this" {
   network_interface {
     bridge = var.network
   }
}

bjvrielink avatar Apr 01 '22 06:04 bjvrielink