From 74482abc5bf300c6d909ffd9ffd17be6ba04ba72 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Wed, 11 Feb 2015 04:11:04 +0000 Subject: [PATCH] Refactoring multiple results --- .../resource_openstack_compute_instance_v2.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index b4f51cc1d..5b03577f4 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -674,10 +674,14 @@ func getFloatingIPs(networkingClient *gophercloud.ServiceClient) ([]floatingips. func getImageID(client *gophercloud.ServiceClient, d *schema.ResourceData) (string, error) { imageId := d.Get("image_id").(string) - imageName := d.Get("image_name").(string) - imageCount := 0 - if imageId == "" && imageName != "" { + if imageId != "" { + return imageId, nil + } + + imageCount := 0 + imageName := d.Get("image_name").(string) + if imageName != "" { pager := images.ListDetail(client, &images.ListOpts{ Name: imageName, }) @@ -705,11 +709,5 @@ func getImageID(client *gophercloud.ServiceClient, d *schema.ResourceData) (stri return "", fmt.Errorf("Found %d images matching %s", imageCount, imageName) } } - - if imageId == "" && imageName == "" { - return "", fmt.Errorf("Neither an image ID nor an image name were able to be determined.") - } - - return imageId, nil - + return "", fmt.Errorf("Neither an image ID nor an image name were able to be determined.") }