From d2d27923df769990fa239b24bb1a769ebe60eac4 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 12 Sep 2016 10:30:45 +0200 Subject: [PATCH] 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. --- .../cloudstack/resource_cloudstack_vpc.go | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index 44ce692125e2..3456d1c3d1d4 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -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) } }