Make name optional on cloudstack_instance resource
This commit matches the behaviour of the cloudstack_instance resource to the documentation at [1], which indicates that the virtual machine name is optional. This also changes the update logic to allow it to be updated as described in [2]. [1] http://cloudstack.apache.org/api/apidocs-4.8/domain_admin/deployVirtualMachine.html [2] http://cloudstack.apache.org/api/apidocs-4.8/domain_admin/updateVirtualMachine.html
This commit is contained in:
parent
01b3e215d7
commit
63008b857f
|
@ -22,7 +22,8 @@ func resourceCloudStackInstance() *schema.Resource {
|
|||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
|
@ -128,14 +129,18 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
|||
p := cs.VirtualMachine.NewDeployVirtualMachineParams(serviceofferingid, templateid, zone.Id)
|
||||
|
||||
// Set the name
|
||||
name := d.Get("name").(string)
|
||||
p.SetName(name)
|
||||
name, hasName := d.GetOk("name")
|
||||
if hasName {
|
||||
p.SetName(name.(string))
|
||||
}
|
||||
|
||||
// Set the display name
|
||||
if displayname, ok := d.GetOk("display_name"); ok {
|
||||
p.SetDisplayname(displayname.(string))
|
||||
} else {
|
||||
p.SetDisplayname(name)
|
||||
if hasName {
|
||||
p.SetDisplayname(name.(string))
|
||||
}
|
||||
}
|
||||
|
||||
if zone.Networktype == "Advanced" {
|
||||
|
@ -244,6 +249,25 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
|||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
if d.HasChange("name") {
|
||||
log.Printf("[DEBUG] Name for %s changed to %s, starting update", d.Id(), name)
|
||||
|
||||
// Create a new parameter struct
|
||||
p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
|
||||
|
||||
// Set the new name
|
||||
p.SetName(d.Get("name").(string))
|
||||
|
||||
// Update the display name
|
||||
_, err := cs.VirtualMachine.UpdateVirtualMachine(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error updating the name for instance %s: %s", name, err)
|
||||
}
|
||||
|
||||
d.SetPartial("name")
|
||||
}
|
||||
|
||||
// Check if the display name is changed and if so, update the virtual machine
|
||||
if d.HasChange("display_name") {
|
||||
log.Printf("[DEBUG] Display name changed for %s, starting update", name)
|
||||
|
|
Loading…
Reference in New Issue