From b3438d07d69fd3d92ad865a07d8e116ae5a0da60 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Wed, 11 Feb 2015 05:33:04 +0000 Subject: [PATCH] This commit enables both the image_id and the image_name to be computed, so that specifying one will populate the other. --- .../resource_openstack_compute_instance_v2.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index 0a7b1b624..fbc7a7dd7 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -45,12 +45,14 @@ func resourceComputeInstanceV2() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + Computed: true, DefaultFunc: envDefaultFunc("OS_IMAGE_ID"), }, "image_name": &schema.Schema{ Type: schema.TypeString, Optional: true, ForceNew: true, + Computed: true, DefaultFunc: envDefaultFunc("OS_IMAGE_NAME"), }, "flavor_id": &schema.Schema{ @@ -353,6 +355,18 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err } d.Set("flavor_name", flavor.Name) + imageId, ok := server.Image["id"].(string) + if !ok { + return fmt.Errorf("Error setting OpenStack server's image: %v", server.Image) + } + d.Set("image_id", imageId) + + image, err := images.Get(computeClient, imageId).Extract() + if err != nil { + return err + } + d.Set("image_name", image.Name) + return nil }