-
Notifications
You must be signed in to change notification settings - Fork 701
cloud: add terraform migrate cluster resource doc #20659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ti-chi-bot
merged 13 commits into
pingcap:master
from
FingerLeader:add-terraform-migrate-doc
May 23, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
12e04a4
add terraform migrate cluster resource doc
FingerLeader 35b0c9b
resolve comments
FingerLeader 88c9e95
update the way to import
FingerLeader 987a7df
add a link
FingerLeader 7b691b8
Apply suggestions from code review
FingerLeader 41a09f7
Apply suggestions from code review
FingerLeader 72e85bf
Update tidb-cloud/terraform-migrate-cluster-resource.md
FingerLeader 2938489
remove next step
FingerLeader d7e9e57
Apply suggestions from code review
FingerLeader e45fcde
Update tidb-cloud/terraform-migrate-cluster-resource.md
FingerLeader 4116487
Update tidb-cloud/terraform-migrate-cluster-resource.md
FingerLeader c5b812c
Update tidb-cloud/terraform-migrate-cluster-resource.md
FingerLeader f9ad628
Apply suggestions from code review
qiancai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
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. | ||
--- | ||
|
||
# Migrate Cluster Resource to 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 `.tf` configuration for your cluster resource. To learn more about it, see [Generating configuration](https://developer.hashicorp.com/terraform/language/import/generating-configuration) in Terraform documentation. | ||
|
||
## Prerequisites | ||
|
||
- Upgrade to [TiDB Cloud Terraform Provider v0.4.0 or later](https://registry.terraform.io/providers/tidbcloud/tidbcloud/latest) | ||
|
||
## Step 1. Identify the `tidbcloud_cluster` resource to migrate | ||
|
||
1. List all `tidbcloud_cluster` resources: | ||
|
||
```shell | ||
terraform state list | grep "tidbcloud_cluster" | ||
``` | ||
|
||
2. Choose a target cluster resource to migrate and get its cluster `id` for later use: | ||
|
||
```shell | ||
terraform state show ${your_target_cluster_resource} | grep ' id ' | ||
``` | ||
|
||
## Step 2. Remove the existing resource from the Terraform state | ||
|
||
Remove your target cluster resource from the Terraform state: | ||
|
||
```shell | ||
terraform state rm ${your_target_cluster_resource} | ||
``` | ||
|
||
## Step 3. Delete the configuration of your target cluster resource | ||
|
||
In your `.tf` file, find the configuration of your target cluster resource and delete the corresponding code. | ||
|
||
## Step 4. Add an import block for the new serverless or dedicated cluster resource | ||
|
||
- If your target cluster is TiDB Cloud Serverless, add the following import block to your `.tf` file, replace `example` with a desired resource name, and replace `${id}` with the cluster ID you get from [Step 1](#step-1-identify-the-tidbcloud_cluster-resource-to-migrate): | ||
|
||
``` | ||
# TiDB Cloud Serverless | ||
import { | ||
to = tidbcloud_serverless_cluster.example | ||
id = "${id}" | ||
} | ||
``` | ||
|
||
- If your target cluster is TiDB Cloud Dedicated, add the following import block to your `.tf` file, replace `example` with a desired resource name, and replace `${id}` with the cluster ID you get from [Step 1](#step-1-identify-the-tidbcloud_cluster-resource-to-migrate): | ||
|
||
``` | ||
# TiDB Cloud Dedicated | ||
import { | ||
to = tidbcloud_dedicated_cluster.example | ||
id = "${id}" | ||
} | ||
``` | ||
|
||
## Step 5. Generate the new configuration file | ||
|
||
Generate the new configuration file for the new serverless or dedicated cluster resource according to the import block: | ||
|
||
```shell | ||
terraform plan -generate-config-out=generated.tf | ||
``` | ||
|
||
Do not specify an existing `.tf` file name in the preceding command. Otherwise, Terraform will return an error. | ||
|
||
## Step 6. Review and apply the generated configuration | ||
|
||
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: | ||
|
||
```shell | ||
tidbcloud_serverless_cluster.example: Importing... | ||
tidbcloud_serverless_cluster.example: Import complete | ||
|
||
Apply complete! Resources: 1 imported, 0 added, 0 changed, 0 destroyed. | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.