---
title: digitalocean_database_cluster
description: Provides a DigitalOcean database cluster resource.
product: Reference
url: https://docs.digitalocean.com/reference/terraform/reference/resources/database_cluster/
last_updated: "2026-11-05"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# digitalocean_database_cluster

Generated on 5 Nov 2026 from Terraform version [`v2.107.0`](https://github.com/digitalocean/terraform-provider-digitalocean/releases/tag/v2.107.0)

Provides a DigitalOcean database cluster resource.

## Example Usage

### Create a new PostgreSQL database cluster

```hcl
resource "digitalocean_database_cluster" "postgres-example" {
  name       = "example-postgres-cluster"
  engine     = "pg"
  version    = "15"
  size       = "db-s-1vcpu-1gb"
  region     = "nyc1"
  node_count = 1
}
```

### Create a new MySQL database cluster

```hcl
resource "digitalocean_database_cluster" "mysql-example" {
  name       = "example-mysql-cluster"
  engine     = "mysql"
  version    = "8"
  size       = "db-s-1vcpu-1gb"
  region     = "nyc1"
  node_count = 1
}
```

### Create a new Valkey database cluster

```hcl
resource "digitalocean_database_cluster" "valkey-example" {
  name       = "example-valkey-cluster"
  engine     = "valkey"
  version    = "8"
  size       = "db-s-1vcpu-1gb"
  region     = "nyc1"
  node_count = 1
}
```

### Create a new Kafka database cluster

```hcl
resource "digitalocean_database_cluster" "kafka-example" {
  name       = "example-kafka-cluster"
  engine     = "kafka"
  version    = "3.5"
  size       = "db-s-2vcpu-2gb"
  region     = "nyc1"
  node_count = 3
}
```

### Create a new MongoDB database cluster

```hcl
resource "digitalocean_database_cluster" "mongodb-example" {
  name       = "example-mongo-cluster"
  engine     = "mongodb"
  version    = "6"
  size       = "db-s-1vcpu-1gb"
  region     = "nyc3"
  node_count = 1
}
```

### Create a new OpenSearch database cluster

```hcl
resource "digitalocean_database_cluster" "opensearch-example" {
  name       = "example-opensearch-cluster"
  engine     = "opensearch"
  version    = "2"
  size       = "db-s-1vcpu-2gb"
  region     = "nyc3"
  node_count = 1
}
```

## Create a new database cluster based on a backup of an existing cluster.

```hcl
resource "digitalocean_database_cluster" "doby" {
  name       = "dobydb"
  engine     = "pg"
  version    = "15"
  size       = "db-s-1vcpu-2gb"
  region     = "nyc1"
  node_count = 1
  tags       = ["production"]
}

resource "digitalocean_database_cluster" "doby_backup" {
  name       = "dobydupe"
  engine     = "pg"
  version    = "15"
  size       = "db-s-1vcpu-2gb"
  region     = "nyc1"
  node_count = 1
  tags       = ["production"]

  backup_restore {
    database_name = "dobydb"
  }

  depends_on = [
    digitalocean_database_cluster.doby
  ]
}
```

## Argument Reference

The following arguments are supported:

- `name` - (Required) The name of the database cluster.
- `engine` - (Required) Database engine used by the cluster (ex. `pg` for PostreSQL, `mysql` for MySQL, `valkey` for Valkey, `mongodb` for MongoDB, or `kafka` for Kafka).
- `size` - (Required) Database Droplet size associated with the cluster (ex. `db-s-1vcpu-1gb`). See the DigitalOcean API for a [list of valid size slugs](https://docs.digitalocean.com/reference/api/reference/databases/index.html.md#databases_list_options).
- `region` - (Required) DigitalOcean region where the cluster will reside.
- `node_count` - (Required) Number of nodes that will be included in the cluster. For `kafka` clusters, this must be 3.
- `version` - (Required) Engine version used by the cluster (ex. `14` for PostgreSQL 14). When this value is changed, a call to the [Upgrade major Version for a Database](https://docs.digitalocean.com/reference/api/reference/databases/index.html.md#databases_update_major_version) API operation is made with the new version.
- `tags` - (Optional) A list of tag names to be applied to the database cluster.
- `private_network_uuid` - (Optional) The ID of the VPC where the database cluster will be located.
- `project_id` - (Optional) The ID of the project that the database cluster is assigned to. If excluded when creating a new database cluster, it will be assigned to your default project.
- `eviction_policy` - (Optional) A string specifying the eviction policy for a Valkey cluster. Valid values are: `noeviction`, `allkeys_lru`, `allkeys_random`, `volatile_lru`, `volatile_random`, or `volatile_ttl`.
- `sql_mode` - (Optional) A comma separated string specifying the SQL modes for a MySQL cluster.
- `maintenance_window` - (Optional) Defines when the automatic maintenance should be performed for the database cluster.
- `storage_size_mib` - (Optional) Defines the disk size, in MiB, allocated to the cluster. This can be adjusted on MySQL and PostreSQL clusters based on predefined ranges for each slug/droplet size.
- `storage_autoscale` - (Optional) Storage autoscaling configuration for the database cluster.

`storage_autoscale` supports the following:

- `enabled` - (Required) Whether storage autoscaling is enabled for the cluster.
- `threshold_percent` - (Optional) The storage utilization percentage at which autoscaling is triggered.
- `increment_gib` - (Optional) The amount of storage, in GiB, to add when autoscaling is triggered.

`maintenance_window` supports the following:

- `day` - (Required) The day of the week on which to apply maintenance updates. May be one of `monday` through `sunday`.
- `hour` - (Required) The hour in UTC at which maintenance updates will be applied as a string in 24 hour format, e.g. `13:00`.
- `backup_restore` - (Optional) Create a new database cluster based on a backup of an existing cluster.

`backup_restore` supports the following:

- `database_name` - (Required) The name of an existing database cluster from which the backup will be restored.
- `backup_created_at` - (Optional) The timestamp of an existing database cluster backup in ISO8601 combined date and time format. The most recent backup will be used if excluded.

This resource supports [customized create and delete timeouts](https://www.terraform.io/docs/language/resources/syntax.html#operation-timeouts). The default timeout is 30 minutes.

## Attributes Reference

In addition to the above arguments, the following attributes are exported:

- `id` - The ID of the database cluster.
- `urn` - The uniform resource name of the database cluster.
- `host` - Database cluster’s hostname.
- `private_host` - Same as `host`, but only accessible from resources within the account and in the same region.
- `port` - Network port that the database cluster is listening on.
- `uri` - The full URI for connecting to the database cluster.
- `private_uri` - Same as `uri`, but only accessible from resources within the account and in the same region.
- `database` - Name of the cluster’s default database.
- `user` - Username for the cluster’s default user.
- `password` - Password for the cluster’s default user.
- `metrics_endpoints` - A list of metrics endpoints for the database cluster, providing URLs to access Prometheus-compatible metrics.

OpenSearch clusters will have the following additional attributes with connection details for their dashboard:

- `ui_host` - Hostname for the OpenSearch dashboard.
- `ui_port` - Network port that the OpenSearch dashboard is listening on.
- `ui_uri` - The full URI for connecting to the OpenSearch dashboard.
- `ui_database` - Name of the OpenSearch dashboard db.
- `ui_user` - Username for OpenSearch dashboard’s default user.
- `ui_password` - Password for the OpenSearch dashboard’s default user.

## Import

Database clusters can be imported using the `id` returned from DigitalOcean, e.g.

```
terraform import digitalocean_database_cluster.mycluster 245bcfd0-7f31-4ce6-a2bc-475a116cca97
```