diff options
author | Zbigniew Kostrzewa <zkostrzewa@gmail.com> | 2017-07-14 07:29:28 +0200 |
---|---|---|
committer | Flavio Castelli <flavio@castelli.me> | 2017-07-15 12:35:01 +0200 |
commit | 9754465f2e30381186621695e499b55c151f75f9 (patch) | |
tree | 428df653a9e34077b4c7ed1d90dbde7cb225e1ac | |
parent | 612d0af3ec4bb23bdebdf878d7f8970517c755cc (diff) | |
download | terraform-provider-libvirt-9754465f2e30381186621695e499b55c151f75f9.tar terraform-provider-libvirt-9754465f2e30381186621695e499b55c151f75f9.tar.gz |
Fix crash occuring when domain is in state file but doesn't exist in libvirt.
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 5861eeea..924467a6 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -156,9 +156,17 @@ func resourceLibvirtDomainExists(d *schema.ResourceData, meta interface{}) (bool if virConn == nil { return false, fmt.Errorf("The libvirt connection was nil.") } + domain, err := virConn.LookupDomainByUUIDString(d.Id()) + if err != nil { + if err.(libvirt.Error).Code == libvirt.ERR_NO_DOMAIN { + return false, nil + } + return false, err + } defer domain.Free() - return err == nil, err + + return true, nil } func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error { |