Skip to content

Commit

Permalink
fix(server): do not try to delete non-existent interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Nov 7, 2024
1 parent bd9ff59 commit e70dd80
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/service/server/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ func updateServerNetworkInterfaces(ctx context.Context, svc *service.Service, d
newNetworkInterfaces := make([]map[string]interface{}, n)
networkInterfaces := interfacesToMap(d.Get("network_interface").([]interface{}))
modifiedInterfaces := make(map[int]*upcloud.Interface)
indices := make(map[int]bool)

// Try to modify existing server interfaces
var i int
var val map[string]interface{}
for _, iface := range s.Networking.Interfaces {
indices[iface.Index] = true
i, val, networkInterfaces = findInterfaceFromState(networkInterfaces, iface.Index, iface.IPAddresses[0].Address, iface.Type)

// Remove interface if it has been removed from configuration
Expand Down Expand Up @@ -253,13 +255,12 @@ func updateServerNetworkInterfaces(ctx context.Context, svc *service.Service, d
network = val["network"].(string)
}

err = svc.DeleteNetworkInterface(ctx, &request.DeleteNetworkInterfaceRequest{
ServerUUID: d.Id(),
Index: index,
})
if err != nil {
var ucProb *upcloud.Problem
if errors.As(err, &ucProb) && ucProb.Type != upcloud.ErrCodeInterfaceNotFound {
if exists := indices[index]; exists {
err = svc.DeleteNetworkInterface(ctx, &request.DeleteNetworkInterfaceRequest{
ServerUUID: d.Id(),
Index: index,
})
if err != nil {
return err
}
}
Expand Down

0 comments on commit e70dd80

Please sign in to comment.