Skip to content

Commit

Permalink
Fix delete retries and detach errors with VPC2s (#399)
Browse files Browse the repository at this point in the history
* Use the correct structs for bare metal update

* Fix error formatting on instance VPC2 detach

* Update retry string to check on VPC2 deletion
  • Loading branch information
optik-aper committed Sep 22, 2023
1 parent f0a46c4 commit a569e3a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions vultr/resource_vultr_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ func resourceVultrBareMetalServerDelete(ctx context.Context, d *schema.ResourceD
log.Printf("[INFO] Deleting bare metal server: %s", d.Id())

if vpcIDs, vpcOK := d.GetOk("vpc2_ids"); vpcOK {
detach := &govultr.InstanceUpdateReq{}
detach := &govultr.BareMetalUpdate{}
for _, v := range vpcIDs.(*schema.Set).List() {
detach.DetachVPC2 = append(detach.DetachVPC2, v.(string))
}

if _, _, err := client.Instance.Update(ctx, d.Id(), detach); err != nil {
return diag.Errorf("error detaching VPCs 2.0 prior to deleting instance %s : %v", d.Id(), err)
if _, _, err := client.BareMetalServer.Update(ctx, d.Id(), detach); err != nil {
return diag.Errorf("error detaching VPC2s prior to deleting bare-metal server %s : %v", d.Id(), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vultr/resource_vultr_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ func resourceVultrInstanceDelete(ctx context.Context, d *schema.ResourceData, me
}

if _, _, err := client.Instance.Update(ctx, d.Id(), detach); err != nil {
return diag.Errorf("error detaching VPCs 2.0 prior to deleting instance %s : %v", d.Id(), err)
return diag.Errorf("error detaching VPC2s prior to deleting instance %s : %v", d.Id(), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vultr/resource_vultr_vpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func resourceVultrVPC2Delete(ctx context.Context, d *schema.ResourceData, meta i
return nil
}

if strings.Contains(err.Error(), "VPC 2.0 is attached") {
if strings.Contains(err.Error(), "servers are attached to this VPC 2.0 network:") {
return retry.RetryableError(fmt.Errorf("cannot remove attached VPC 2.0: %s", err.Error()))
}

Expand Down

0 comments on commit a569e3a

Please sign in to comment.