This commit enables both the image_id and the image_name to be

computed, so that specifying one will populate the other.
This commit is contained in:
Joe Topjian 2015-02-11 05:33:04 +00:00 committed by Jon Perritt
parent 768292c069
commit b3438d07d6
1 changed files with 14 additions and 0 deletions

View File

@ -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
}