Merge branch 'cloudstack-group' of https://github.com/jefflaplante/terraform into f-cloustack-group
This commit is contained in:
commit
55d4e3cda7
|
@ -110,6 +110,12 @@ func resourceCloudStackInstance() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"group": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,6 +224,11 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||||
p.SetUserdata(ud)
|
p.SetUserdata(ud)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is a group supplied, add it to the parameter struct
|
||||||
|
if group, ok := d.GetOk("group"); ok {
|
||||||
|
p.SetGroup(group.(string))
|
||||||
|
}
|
||||||
|
|
||||||
// Create the new instance
|
// Create the new instance
|
||||||
r, err := cs.VirtualMachine.DeployVirtualMachine(p)
|
r, err := cs.VirtualMachine.DeployVirtualMachine(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,6 +266,7 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
||||||
d.Set("display_name", vm.Displayname)
|
d.Set("display_name", vm.Displayname)
|
||||||
d.Set("network_id", vm.Nic[0].Networkid)
|
d.Set("network_id", vm.Nic[0].Networkid)
|
||||||
d.Set("ip_address", vm.Nic[0].Ipaddress)
|
d.Set("ip_address", vm.Nic[0].Ipaddress)
|
||||||
|
d.Set("group", vm.Group)
|
||||||
|
|
||||||
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||||
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
|
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
|
||||||
|
@ -290,6 +302,26 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||||
d.SetPartial("display_name")
|
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
|
// Attributes that require reboot to update
|
||||||
if d.HasChange("name") || d.HasChange("service_offering") || d.HasChange("keypair") {
|
if d.HasChange("name") || d.HasChange("service_offering") || d.HasChange("keypair") {
|
||||||
// Before we can actually make these changes, the virtual machine must be stopped
|
// Before we can actually make these changes, the virtual machine must be stopped
|
||||||
|
|
|
@ -31,6 +31,8 @@ The following arguments are supported:
|
||||||
|
|
||||||
* `display_name` - (Optional) The display name of the instance.
|
* `display_name` - (Optional) The display name of the instance.
|
||||||
|
|
||||||
|
* `group` - (Optional) The group name of the instance.
|
||||||
|
|
||||||
* `service_offering` - (Required) The name or ID of the service offering used
|
* `service_offering` - (Required) The name or ID of the service offering used
|
||||||
for this instance.
|
for this instance.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue