fix: P0.2 — auto-cleanup not_created orphan instances on adopt

This commit is contained in:
“Naeel”
2026-06-30 17:33:17 +04:00
parent df450b1eec
commit ce28906d32
@@ -130,7 +130,13 @@ func adoptExistingInstanceOnCreate(ctx context.Context, client *core.UniversalCl
}
status := normalizeStatus(existing.ExplainedStatus)
if isStatusNotCreated(status) {
return "", fmt.Errorf("инстанс с resource_name %s найден в состоянии Not Created; удалите его в Личном кабинете (Управление облаком) и повторите apply. %s", displayName, formatInstanceDetails(existing, serviceID, displayName))
// P0.2: авто-cleanup orphan-инстанса при adopt_existing_on_create=true.
// Вместо «удалите вручную в ЛК» — удаляем сами и создаём новый.
if err := client.RunInstanceOperationUniversal(ctx, existing.InstanceUid, "delete", nil); err != nil {
return "", fmt.Errorf("не удалось авто-удалить orphan-инстанс %s (статус: %s): %w. %s",
existing.InstanceUid, status, err, formatInstanceDetails(existing, serviceID, displayName))
}
return client.CreateGenericInstanceUniversalV6(ctx, serviceID, displayName, params)
}
if isStatusRunning(status) {
// Валидация ref-параметров для running инстанса при adopt