dmacvicar / terraform-provider-libvirt

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

fix: Network is not started if inactive #1095 #1097

Open ne-bknn opened 2 months ago

ne-bknn commented 2 months ago

Includes network activity status in terraform state, thus allowing terraform to update network resource in case it is inactive (e.g. after hypervisor reboot or virsh net-destroy)

Network activity is checked in Update method, but not in Read, its not recorded in local state. This makes terraform think that network should not be updated (since the state matches recorded one). Then, VM initialization fails, since it depends on an inactive network.

First brought up in #1095.

ne-bknn commented 2 months ago

Uh, actually referenced here with explanation why this isn't yet fixed: #947

I've just copy-pasted running variable from libvirt_domain schema. My reasoning is that they are semantically equivalent, so if this variable config is correct for libvirt_domain it should be correct for libvirt_network. What's the catch?

Full disclosure: only user-level experience with terraform, no experience with libvirt. My assumptions may be horribly wrong.

dmacvicar commented 2 months ago

Thanks for the attempt.

It is more complicated than that. It requires on acting on the status based of what you read to bring the network up if it was up last time and it is now down.

ne-bknn commented 2 months ago

I understand that I can be and most probably is wrong, but I do not understand why. Network state is checked in Update and Update brings it up if its not up: https://github.com/dmacvicar/terraform-provider-libvirt/blob/f5a8334bbecd7ca778739f34d50b71e9c479e795/libvirt/resource_libvirt_network.go#L313-L323

We just have to signal to terraform that network state is not the expected one. My (manual and naive) tests show that it works - if the network is up, it won't be updated, if it is down, it will be. What case I fail to see?