Skip to content

Commit 083b89d

Browse files
committed
fix: reorder disks to match libvirt return order
Place cdrom disk last in concat since libvirt returns virtio disks before sata/ide devices. This prevents 'Provider produced inconsistent result after apply' errors with dmacvicar/libvirt provider 0.9.x. Also expand lifecycle ignore_changes to specifically target disks and graphics attributes that exhibit ordering drift.
1 parent 29a8a43 commit 083b89d

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

main.tf

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ resource "libvirt_domain" "vm" {
6060
}
6161

6262
devices = {
63+
# Disk ordering: boot disk, extra volumes, then cdrom LAST
64+
# libvirt returns disks sorted by bus type (virtio before sata/ide)
65+
# so we must define them in that order to avoid provider inconsistency errors
6366
disks = concat(
6467
[
6568
{
@@ -73,33 +76,35 @@ resource "libvirt_domain" "vm" {
7376
dev = "vda"
7477
bus = "virtio"
7578
}
76-
},
77-
{
79+
}
80+
],
81+
[
82+
for idx, vol in libvirt_volume.extra : {
7883
source = {
7984
volume = {
8085
pool = var.storage_pool
81-
volume = libvirt_volume.cloudinit.name
86+
volume = vol.name
8287
}
8388
}
8489
target = {
85-
dev = "hda"
86-
bus = "sata"
90+
dev = "vd${substr("bcdefghij", idx, 1)}"
91+
bus = "virtio"
8792
}
88-
device = "cdrom"
8993
}
9094
],
9195
[
92-
for idx, vol in libvirt_volume.extra : {
96+
{
9397
source = {
9498
volume = {
9599
pool = var.storage_pool
96-
volume = vol.name
100+
volume = libvirt_volume.cloudinit.name
97101
}
98102
}
99103
target = {
100-
dev = "vd${substr("cdefghij", idx, 1)}"
101-
bus = "virtio"
104+
dev = "sda"
105+
bus = "sata"
102106
}
107+
device = "cdrom"
103108
}
104109
]
105110
)
@@ -145,7 +150,14 @@ resource "libvirt_domain" "vm" {
145150
}
146151

147152
lifecycle {
148-
ignore_changes = [devices]
153+
# Ignore device ordering changes - libvirt provider 0.9.x has a bug where
154+
# it returns disks in a different order than specified, causing
155+
# "Provider produced inconsistent result after apply" errors.
156+
# Also ignore graphics changes due to similar provider bugs.
157+
ignore_changes = [
158+
devices.disks,
159+
devices.graphics,
160+
]
149161
}
150162
}
151163

0 commit comments

Comments
 (0)