Skip to main content
ClickHouse Managed Postgres services can be created and managed using the clickhouse_postgres_service resource in the ClickHouse Terraform provider. This page covers provider setup and configuration examples for the resource and its companion data sources.
This resource is in alpha and its behavior may change in future provider versions. It ships in the regular provider build. This page documents provider version v3.21.0 and later, which changed how credentials are managed; earlier versions behave differently and as of July 31, 2026 no longer work correctly. See the provider releases for details.
Upgrade to provider v3.21.0 before July 31, 2026As of July 31, 2026, the Managed Postgres API ceased to return the superuser password and connection string in its responses; credentials are returned only when a service is created or its password is reset. Provider versions v3.21.0 and later work identically before and after this change. Older provider versions rely on the API echoing credentials: as of July 31, 2026, they no longer populate connection_string, and a service created without a declared password succeeds while the generated password is never captured anywhere.Upgrade before July 31, 2026. Your state migrates automatically on the first plan or apply with v3.21.0. If any of your services rely on a server-generated password (no password in configuration), recover it first with terraform state pull and declare it, since v3.21.0 requires password or password_wo for a standard service.

Provider setup

Add the ClickHouse provider to your Terraform configuration:
See Managing API keys for instructions on creating an API key to use with the provider.

Resource overview

The clickhouse_postgres_service resource has the following arguments: The following attributes are read-only and populated by ClickHouse Cloud after creation: id, state, created_at, is_primary, hostname, port, and username. There is no connection_string attribute (removed in v3.21.0): build connection URIs from hostname, port, username, and the password you declare, for example postgres://${username}:${password}@${hostname}:${port}/postgres?sslmode=require.
The password is stored in plain text in your Terraform state. Protect your state file accordingly, for example with a remote backend using encryption at rest, or use password_wo to keep the password out of state entirely.

Create a service

A standard service must declare password or password_wo. The value must be at least 12 characters with at least one lowercase letter, one uppercase letter, and one digit. password_wo (with password_wo_version) applies the same password rules but is never stored in state; change password_wo_version to rotate. Because the API does not return credentials, Terraform must stay the only writer of the password: a password rotated outside Terraform (console or API) is not detected, and the next Terraform-driven rotation reasserts the declared value.

High availability

The ha_type argument controls the number of standby replicas: ha_type is mutable post-create; changing it triggers an HA transition. See High availability for details.

Read replicas

Set read_replica_of to the id of a primary service to create a streaming read replica. A replica inherits the primary’s cloud_provider, region, postgres_version, and superuser — omit those (and password):
See Read replicas for details.

Point-in-time restore

Set restore_to_point_in_time to create a service by restoring another service’s backup to a point in time. cloud_provider, region, and postgres_version are inherited from the source (omit them); size and ha_type must be omitted:
The whole block is create-time only: changing source_id or restore_target, or removing the block, destroys and recreates the service. See Backup and restore for details.

Data sources

Three companion data sources let you look up existing services:

Importing existing services

Existing Managed Postgres services can be imported into Terraform state using the service ID:
Import does not recover the password (the API does not return it). After importing, the first apply rotates the service to the password or password_wo declared in your configuration.

Unsupported operations

The following are intentionally absent from the resource schema:
  • Operational commands (restart, promote, switchover).
  • IP allowlists, private endpoints, backup configuration, maintenance windows, customer-managed encryption keys, and BYOC.
  • Configurable lifecycle timeouts — there is no timeouts {} block.
Last modified on July 22, 2026