diff options
author | Thomas Hipp <thipp@suse.de> | 2017-08-07 16:24:54 +0200 |
---|---|---|
committer | Flavio Castelli <flavio@castelli.me> | 2017-08-08 09:40:23 +0200 |
commit | 1aac0d73977bf5d9e9bac462d2302d28debe8605 (patch) | |
tree | d0906f97420a26188ca3a9a5a9fc5d2bb949fd54 /libvirt | |
parent | cb499833b53b90c8dd4da2c1ec83c86ecae7e7ea (diff) | |
download | terraform-provider-libvirt-1aac0d73977bf5d9e9bac462d2302d28debe8605.tar terraform-provider-libvirt-1aac0d73977bf5d9e9bac462d2302d28debe8605.tar.gz |
network: ensure networks are recreated
Ensure that networks are only free'd if there are no errors.
Furthermore, make sure that networks are recreated if they cannot be
found on the remote.
This fixes #74.
Signed-off-by: Thomas Hipp <thipp@suse.de>
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/resource_libvirt_network.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libvirt/resource_libvirt_network.go b/libvirt/resource_libvirt_network.go index 344440c8..a34c9c13 100644 --- a/libvirt/resource_libvirt_network.go +++ b/libvirt/resource_libvirt_network.go @@ -116,7 +116,16 @@ func resourceLibvirtNetworkExists(d *schema.ResourceData, meta interface{}) (boo return false, fmt.Errorf("The libvirt connection was nil.") } network, err := virConn.LookupNetworkByUUIDString(d.Id()) + if err != nil { + // If the network couldn't be found, don't return an error otherwise + // Terraform won't create it again. + if lverr, ok := err.(libvirt.Error); ok && lverr.Code == libvirt.ERR_NO_NETWORK { + return false, nil + } + return false, err + } defer network.Free() + return err == nil, err } @@ -126,6 +135,9 @@ func resourceLibvirtNetworkUpdate(d *schema.ResourceData, meta interface{}) erro return fmt.Errorf("The libvirt connection was nil.") } network, err := virConn.LookupNetworkByUUIDString(d.Id()) + if err != nil { + return err + } defer network.Free() d.Partial(true) |