Skip to content

Commit

Permalink
provider/cloudstack: fix vpc renaming (#8784)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Sander van Harmelen authored Sep 12, 2016
1 parent 94b37e4 commit d2d2792
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions builtin/providers/cloudstack/resource_cloudstack_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
}
}

Expand Down

0 comments on commit d2d2792

Please sign in to comment.