provider/cloudstack: fix vpc renaming (#8784)
* fixed vpc rename bug * Tweak the suggested fix There was an assertion error in the fix, and after discussing we felt it was better to split the two changes to make them independant.
This commit is contained in:
parent
94b37e4b9c
commit
d2d27923df
|
@ -182,8 +182,26 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
|
|||
func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Check if the name or display text is changed
|
||||
if d.HasChange("name") || d.HasChange("display_text") {
|
||||
name := d.Get("name").(string)
|
||||
|
||||
// Check if the name is changed
|
||||
if d.HasChange("name") {
|
||||
// Create a new parameter struct
|
||||
p := cs.VPC.NewUpdateVPCParams(d.Id())
|
||||
|
||||
// Set the new name
|
||||
p.SetName(name)
|
||||
|
||||
// Update the VPC
|
||||
_, err := cs.VPC.UpdateVPC(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error updating name of VPC %s: %s", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the display text is changed
|
||||
if d.HasChange("display_text") {
|
||||
// Create a new parameter struct
|
||||
p := cs.VPC.NewUpdateVPCParams(d.Id())
|
||||
|
||||
|
@ -192,14 +210,15 @@ func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error
|
|||
if !ok {
|
||||
displaytext = d.Get("name")
|
||||
}
|
||||
// Set the (new) display text
|
||||
|
||||
// Set the new display text
|
||||
p.SetDisplaytext(displaytext.(string))
|
||||
|
||||
// Update the VPC
|
||||
_, err := cs.VPC.UpdateVPC(p)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error updating VPC %s: %s", d.Get("name").(string), err)
|
||||
"Error updating display test of VPC %s: %s", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue