diff --git a/internal/providers/outscale_oapi/outscale_oapi.go b/internal/providers/outscale_oapi/outscale_oapi.go index 65e149f..e703929 100644 --- a/internal/providers/outscale_oapi/outscale_oapi.go +++ b/internal/providers/outscale_oapi/outscale_oapi.go @@ -645,7 +645,7 @@ func (provider *OutscaleOAPI) unlinkRouteTable(RouteTableId string) error { return nil } for _, link := range *routeTable.LinkRouteTables { - if link.LinkRouteTableId == nil { + if link.LinkRouteTableId == nil || link.GetMain() { continue } linkId := *link.LinkRouteTableId @@ -667,6 +667,19 @@ func (provider *OutscaleOAPI) unlinkRouteTable(RouteTableId string) error { return nil } +func (provider *OutscaleOAPI) isMainRouteTable(RouteTableId string) bool { + routeTable := provider.cache.routeTables[RouteTableId] + if routeTable == nil || routeTable.LinkRouteTables == nil { + return false + } + for _, link := range *routeTable.LinkRouteTables { + if link.GetMain() { + return true + } + } + return false +} + func (provider *OutscaleOAPI) deleteRouteTables(routeTables []Object) { if len(routeTables) == 0 { return @@ -675,6 +688,10 @@ func (provider *OutscaleOAPI) deleteRouteTables(routeTables []Object) { if provider.unlinkRouteTable(routeTable) != nil { continue } + if provider.isMainRouteTable(routeTable) { + log.Printf("Skipping deletion of Main RouteTable %v\n", routeTable) + continue + } log.Printf("Deleting route table %s... ", routeTable) deletionOpts := osc.DeleteRouteTableRequest{RouteTableId: routeTable} _, httpRes, err := provider.client.RouteTableApi.