If you used the Terraform provider to manage CockroachDB Serverless clusters that have been migrated to CockroachDB Basic, your recipes must be updated to work with CockroachDB Basic.
Before you begin
Before you start this tutorial, you must- Install Terraform.
- Create a and in the CockroachDB Cloud Console, and assign it the Cluster Creator or Cluster Admin role at the organization scope. Refer to .
Create the Terraform configuration file
In this tutorial, you will create a CockroachDB Basic cluster.-
In a terminal create a new file named
main.tfwith the following contents:- Optionally, include the
versionattribute in thecockroachnested block to specify a version of the provider. If you do not include theversionattribute, Terraform will use the latest provider version. - Replace
cockroach-basicwith a name for the cluster. - Set
cloud_providertoAWSAZURE, orGCP. - Under
serverless {}, optionally set values forresource_unit_limitandstorage_mib_limits. - Under
regions, add the names of one or more regions for the cluster. - To optionally enable , set
delete_protectiontotrue.
- Optionally, include the
-
Create an environment variable named
COCKROACH_API_KEY. Copy the from the CockroachDB Cloud console and create theCOCKROACH_API_KEYenvironment variable:Where is the API key you copied from the CockroachDB Cloud Console.
Provision a cluster
-
Initialize the provider:
This reads the
main.tfconfiguration file. The-upgradeflag ensures you are using the latest version of the provider. -
Create the Terraform plan. This shows the actions the provider will take, but won’t perform them:
-
Create the cluster:
Enter
yeswhen prompted to apply the plan and create the cluster.
yes to apply the changes.
Before you begin
Before you start this tutorial, you must- Install Terraform.
- Create a and in the CockroachDB Cloud Console, and assign it the Cluster Creator or Cluster Admin role at the organization scope. Refer to .
Create the Terraform configuration file
In this tutorial, you will create a CockroachDB Standard cluster.-
In a terminal create a new file named
main.tfwith the following contents:-
Optionally, include the
versionattribute in thecockroachnested block to specify a version of the provider. If you do not include theversionattribute, Terraform will use the latest provider version. -
Replace
cockroach-standardwith a name for the cluster. -
Set
cloud_providertoAWSAZURE, orGCP. - Under usage_limits, set provisioned_virtual_cpus to the required maximum vCPUs for the cluster.
- Under regions, add the names of one or more regions for the cluster.
-
To optionally enable , set
delete_protectiontotrue. You may also want to configure the settings your CockroachDB Standard cluster takes automatically. To do so, include thebackup_configattribute in thecockroach_clusterresource:You can modify the of managed backups only once with one of the following: the , the , or Terraform. To modify the setting again, contact the . For details on thebackup_configsettings, refer to .
-
Optionally, include the
-
Create an environment variable named
COCKROACH_API_KEY. Copy the from the CockroachDB Cloud console and create theCOCKROACH_API_KEYenvironment variable:Where is the API key you copied from the CockroachDB Cloud Console.
Provision a cluster
-
Initialize the provider:
This reads the
main.tfconfiguration file. The-upgradeflag ensures you are using the latest version of the provider. -
Create the Terraform plan. This shows the actions the provider will take, but won’t perform them:
-
Create the cluster:
Enter
yeswhen prompted to apply the plan and create the cluster.
yes to apply the changes.
Get information about a cluster
Theterraform show command shows detailed information of your cluster resources.
Change a cluster’s plan
To change a CockroachDB Basic cluster’s plan to CockroachDB Standard in place, or to change a CockroachDB Standard cluster to CockroachDB Basic using Terraform or the .To migrate between CockroachDB Advanced and either CockroachDB Standard or CockroachDB Basic, you must create and configure a new cluster, create a self-managed backup of the existing cluster’s data, and restore the backup to the new cluster. Refer to . Migration in place is not supported.
-
Edit the cluster’s Terraform template:
-
Change
plantoSTANDARD. -
Replace the contents of
serverless {}(which may be empty) with the provisioned vCPUs for the cluster. This field is required for CockroachDB Standard. It is not possible to set storage limitations on CockroachDB Standard.
-
Change
-
Apply the template:
-
Edit the cluster’s Terraform template:
-
Change
plantoBASIC. -
Replace the contents of
serverless {...}with optional limits for Request Units and Storage. Theprovisioned_virtual_cpusfield is not supported on CockroachDB Basic. - Remove configurations for features that are unsupported on CockroachDB Basic, such as private connectivity. Otherwise, applying the template will fail.
-
Change
-
Apply the template:
PATCH request to the updating the plan and serverless.usage_limits as needed. The following example sets the plan to STANDARD and updates the usage_limits to provision VCPUs as required for a Standard plan:
Delete a cluster
Sending adestroy command permanently deletes the cluster and all the data within the cluster. Deleted clusters can not be restored.
If you want to delete a cluster managed by Terraform, run the following command:
yes when prompted to delete the cluster.
Next steps
- Read the CockroachDB Cloud Terraform provider reference docs in the Terraform registry, which provide detailed information on the resources you can manage using Terraform.
- Browse the example recipes in the Terraform Provider’s GitHub repository.
- Refer to the page to configure the managed backups for your CockroachDB Cloud cluster.

