Skip to content

Commit d2d2792

Browse files
author
Sander van Harmelen
authored
provider/cloudstack: fix vpc renaming (hashicorp#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.
1 parent 94b37e4 commit d2d2792

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

builtin/providers/cloudstack/resource_cloudstack_vpc.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,26 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
182182
func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error {
183183
cs := meta.(*cloudstack.CloudStackClient)
184184

185-
// Check if the name or display text is changed
186-
if d.HasChange("name") || d.HasChange("display_text") {
185+
name := d.Get("name").(string)
186+
187+
// Check if the name is changed
188+
if d.HasChange("name") {
189+
// Create a new parameter struct
190+
p := cs.VPC.NewUpdateVPCParams(d.Id())
191+
192+
// Set the new name
193+
p.SetName(name)
194+
195+
// Update the VPC
196+
_, err := cs.VPC.UpdateVPC(p)
197+
if err != nil {
198+
return fmt.Errorf(
199+
"Error updating name of VPC %s: %s", name, err)
200+
}
201+
}
202+
203+
// Check if the display text is changed
204+
if d.HasChange("display_text") {
187205
// Create a new parameter struct
188206
p := cs.VPC.NewUpdateVPCParams(d.Id())
189207

@@ -192,14 +210,15 @@ func resourceCloudStackVPCUpdate(d *schema.ResourceData, meta interface{}) error
192210
if !ok {
193211
displaytext = d.Get("name")
194212
}
195-
// Set the (new) display text
213+
214+
// Set the new display text
196215
p.SetDisplaytext(displaytext.(string))
197216

198217
// Update the VPC
199218
_, err := cs.VPC.UpdateVPC(p)
200219
if err != nil {
201220
return fmt.Errorf(
202-
"Error updating VPC %s: %s", d.Get("name").(string), err)
221+
"Error updating display test of VPC %s: %s", name, err)
203222
}
204223
}
205224

0 commit comments

Comments
 (0)