| title | Migrate Cluster Resource to Serverless or Dedicated Cluster Resource |
|---|---|
| summary | Learn how to migrate a cluster resource to a serverless or dedicated cluster resource. |
Starting from TiDB Cloud Terraform Provider v0.4.0, the tidbcloud_cluster resource is replaced by two new resources: tidbcloud_serverless_cluster and tidbcloud_dedicated_cluster. If you are using TiDB Cloud Terraform Provider v0.4.0 or a later version, you can follow this document to migrate your tidbcloud_cluster resource to the tidbcloud_serverless_cluster or tidbcloud_dedicated_cluster resource.
Tip:
The steps in this document use the configuration generation feature of Terraform to simplify the migration process by automatically recreating the
.tfconfiguration for your cluster resource. To learn more about it, see Generating configuration in Terraform documentation.
-
List all
tidbcloud_clusterresources:terraform state list | grep "tidbcloud_cluster"
-
Choose a target cluster resource to migrate and get its cluster
idfor later use:terraform state show ${your_target_cluster_resource} | grep ' id '
Remove your target cluster resource from the Terraform state:
terraform state rm ${your_target_cluster_resource}In your .tf file, find the configuration of your target cluster resource and delete the corresponding code.
-
If your target cluster is {{{ .starter }}}, add the following import block to your
.tffile, replaceexamplewith a desired resource name, and replace${id}with the cluster ID you get from Step 1:# {{{ .starter }}} import { to = tidbcloud_serverless_cluster.example id = "${id}" } -
If your target cluster is TiDB Cloud Dedicated, add the following import block to your
.tffile, replaceexamplewith a desired resource name, and replace${id}with the cluster ID you get from Step 1:# TiDB Cloud Dedicated import { to = tidbcloud_dedicated_cluster.example id = "${id}" }
Generate the new configuration file for the new serverless or dedicated cluster resource according to the import block:
terraform plan -generate-config-out=generated.tfDo not specify an existing .tf file name in the preceding command. Otherwise, Terraform will return an error.
Review the generated configuration file to ensure it meets your needs. Optionally, you can move the contents of this file to your preferred location.
Then, run terraform apply to import your infrastructure. After applying, the example output is as follows:
tidbcloud_serverless_cluster.example: Importing...
tidbcloud_serverless_cluster.example: Import complete
Apply complete! Resources: 1 imported, 0 added, 0 changed, 0 destroyed.