This applies to ClickHouse Cloud services. It does not apply to ClickHouse Managed Postgres services.
DELETE /v1/organizations/{organizationId}/services/{serviceId} returns HTTP 409 until you turn protection off. The service must also be stopped before it can be deleted. Deletion then runs asynchronously.
Who can change it
Turning protection on or off uses thecontrol-plane:service:delete permission. Organization admins have this permission. See Console roles and permissions.
Turning protection on also requires deletion protection to be available for the organization. ClickHouse Cloud organizations have it. A create or update that sets deletionProtection to true returns HTTP 400 when the organization does not. Turning protection off does not use that check: a request that sets deletionProtection to false is accepted, including for a service that is already protected.
ClickStack services cannot be updated through the Cloud API. Turn their deletion protection on or off in the console.
Turn protection on or off in the console
Open the service and go to Settings. Under Deletion protection, use the switch. The change is saved immediately. The switch is available to anyone withcontrol-plane:service:delete on that service. With protection on, the console refuses the delete action until you turn the switch off.
Set it with the Cloud API
The service object has a boolean field,deletionProtection. Set it when you create a service (POST /v1/organizations/{organizationId}/services) or update one (PATCH /v1/organizations/{organizationId}/services/{serviceId}). Get and list responses include the field. When it is absent, the service is not protected.
Turn protection on:
PATCH .../state with "command": "stop" requires control-plane:service:manage and returns before the service has stopped. A delete while the service is still stopping is rejected. A delete against a protected service returns 409 and leaves the service in place.
Turn protection off:
result.state is stopped, then delete:
Terraform
deletion_protection is not in the latest released provider, v3.43.0. The attribute was added in terraform-provider-clickhouse#799, which is merged and not yet in a release. The example below fails on v3.43.0 with an unsupported argument. Use a provider release after v3.43.0 that includes the attribute.clickhouse_service resource accepts deletion_protection. While it is true, terraform destroy and any change that would replace the service fail. Set it to false and apply that change on its own, then destroy the service.
Removing deletion_protection from the configuration leaves the current setting unchanged.
deletion_protection = true when creating a service needs an API key that can delete all services in the organization. Changing it later needs delete permission on that service.