Added support to read and update group attribute from existing vm state.

This commit is contained in:
Jeff LaPlante 2016-04-11 10:23:19 -07:00
parent ba4ec0097a
commit f840f49fbb
1 changed files with 22 additions and 0 deletions

View File

@ -240,6 +240,8 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("name", vm.Name)
d.Set("display_name", vm.Displayname)
d.Set("ipaddress", vm.Nic[0].Ipaddress)
d.Set("group", vm.Group)
//NB cloudstack sometimes sends back the wrong keypair name, so dont update it
setValueOrID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
@ -277,6 +279,26 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
d.SetPartial("display_name")
}
// Check if the group is changed and if so, update the virtual machine
if d.HasChange("group") {
log.Printf("[DEBUG] Group changed for %s, starting update", name)
// Create a new parameter struct
p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
// Set the new group
p.SetGroup(d.Get("group").(string))
// Update the display name
_, err := cs.VirtualMachine.UpdateVirtualMachine(p)
if err != nil {
return fmt.Errorf(
"Error updating the group for instance %s: %s", name, err)
}
d.SetPartial("group")
}
// Attributes that require reboot to update
if d.HasChange("name") || d.HasChange("service_offering") || d.HasChange("keypair") {
// Before we can actually make these changes, the virtual machine must be stopped