-
Notifications
You must be signed in to change notification settings - Fork 496
Open
Description
When using libvirt_domain with PCI passthrough devices (hostdevs with subsys_pci), any address field (domain, bus, slot, function) that has a value of 0 is incorrectly returned as null by the provider after apply. This causes Terraform/OpenTofu to report "Provider produced inconsistent result after apply" errors and makes it impossible to manage PCI passthrough devices where any address component is 0.
This is extremely common since most PCI devices have domain=0, and many have slot=0 or function=0 (e.g., 0000:03:00.0).
Steps to Reproduce
- Create the following minimal configuration:
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "~> 0.9.0"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
resource "libvirt_volume" "test" {
name = "test-pci-bug.qcow2"
pool = "default"
capacity = 1073741824
target = {
format = {
type = "qcow2"
}
}
}
resource "libvirt_domain" "test" {
name = "test-pci-bug"
memory = 512
vcpu = 1
type = "kvm"
os = {
type = "hvm"
type_arch = "x86_64"
}
devices = {
disks = [
{
source = {
volume = {
pool = "default"
volume = libvirt_volume.test.name
}
}
target = {
dev = "vda"
bus = "virtio"
}
}
]
# PCI passthrough device - update bus to match a real device on your system
# The bug occurs when domain, slot, or function equals 0
hostdevs = [
{
managed = true
subsys_pci = {
source = {
address = {
domain = 0 # This will be returned as null
bus = 3 # Change to match your device
slot = 0 # This will be returned as null
function = 0 # This will be returned as null
}
}
}
}
]
}
}- Run
terraform init && terraform apply
Expected Behavior
Apply should succeed and terraform plan should show "No changes".
Actual Behavior
Apply fails with:
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to libvirt_domain.test, provider "provider[\"registry.opentofu.org/dmacvicar/libvirt\"]"
│ produced an unexpected new value: .devices.hostdevs[0].subsys_pci.source.address.function: was cty.NumberIntVal(0), but now null.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to libvirt_domain.test, provider "provider[\"registry.opentofu.org/dmacvicar/libvirt\"]"
│ produced an unexpected new value: .devices.hostdevs[0].subsys_pci.source.address.slot: was cty.NumberIntVal(0), but now null.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to libvirt_domain.test, provider "provider[\"registry.opentofu.org/dmacvicar/libvirt\"]"
│ produced an unexpected new value: .devices.hostdevs[0].subsys_pci.source.address.domain: was cty.NumberIntVal(0), but now null.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
Metadata
Metadata
Assignees
Labels
No labels