Open agorgl opened 2 years ago
// resourceLibvirtNetworkUpdate updates dynamically some attributes in the network
func resourceLibvirtNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
// check the list of things that can be changed dynamically
// in https://wiki.libvirt.org/page/Networking#virsh_net-update
virConn := meta.(*Client).libvirt
if virConn == nil {
return fmt.Errorf(LibVirtConIsNil)
}
network, err := virConn.NetworkLookupByUUID(parseUUID(d.Id()))
if err != nil {
return fmt.Errorf("can't retrieve network with ID '%s' during update: %s", d.Id(), err)
}
d.Partial(true)
activeInt, err := virConn.NetworkIsActive(network)
if err != nil {
return fmt.Errorf("error when getting network %s status during update: %s", network.Name, err)
}
active := activeInt == 1
if !active {
log.Printf("[DEBUG] Activating network %s", network.Name)
if err := virConn.NetworkCreate(network); err != nil {
return fmt.Errorf("error when activating network %s during update: %s", network.Name, err)
}
}
in resourceLibvirtNetworkUpdate
, which means resourceLibvirtNetworkUpdate
is not called if the network is not update. Because we don't track the active
property in resourceLibvirtNetworkRead
.
But I am not sure what is the best way to track this. A computed attribute? Tell somehow terraform to foce the update even if no parameter from the schema is changed?
When creating a libvirt network without autostart and rebooting the hypervisor, the network and the instances (domains) are inactive / stopped, as expected.
Running
terraform plan
in this scenario we get this:This shows that provider is able to track if the libvirt_domain is running and try to bring it up again, but it does NOT! track the state of the network it is connected to and we manually need to run
virsh net-start network
before runningterraform plan
again in order to get a successful result.