This is the repository for the terraform-provider-tidbcloud, which allows one to use Terraform with TiDB Cloud. Learn more about TiDB Cloud
For general information about Terraform, visit the official website and the GitHub project page.
Resources
- cluster
- backup (not support update)
- restore (not support update and delete)
- import (not support update)
DataSource
Install terraform in Mac. See official doc for other OS.
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
- In a terminal clone the terraform-provider-tidbcloud repository.
git clone git@github.com:tidbcloud/terraform-provider-tidbcloud.git
- Go to the examples/workflows/tidbcloud_serverless_tier directory.
cd examples/workflows/tidbcloud_serverless_tier
- The provider requires an API key set in an environment variable. Copy the API key from the TiDB Cloud console and create the environment variables.
export TIDBCLOUD_PUBLIC_KEY=fake_public_key
export TIDBCLOUD_PRIVATE_KEY=fake_private_key
- Copy
terraform.tfvars.templatestoterraform.tfvarsand edit the cluster settings.
cp terraform.tfvars.templates terraform.tfvars
The examples do not include a password. Enter a strong, unique database password when Terraform prompts, or supply TF_VAR_password from your secret store for non-interactive runs.
- Execute the following commands to create a serverless tier
terraform init
terraform apply --auto-approve
- The example will output the
connection_stringsfor you.
connection_strings = {
"default_user" = "3ybfFe46ZdoSR3b.root"
"standard" = {
"host" = "gateway01.us-west-2.prod.aws.tidbcloud.com"
"port" = 4000
}
"vpc_peering" = {
"host" = ""
"port" = 0
}
}
The connection_strings will be generated after the cluster is available. If you find the output is empty, you can execute the terraform refersh to refresh the state of cluster.
See TiDB Cloud Terraform Integration Overview for more details.
Set public_key and private_key in the provider block, or omit them and set TIDBCLOUD_PUBLIC_KEY and TIDBCLOUD_PRIVATE_KEY in the environment. In CI, inject the keys from your secret store. Keep real keys out of version control.
Rotate keys according to your organization's policy: create a replacement key with the required permissions, update all consumers, verify access, then delete the old key. Revoke potentially compromised keys immediately. See API key management for creation and deletion instructions.
TIDBCLOUD_HOST, TIDBCLOUD_DEDICATED_ENDPOINT, TIDBCLOUD_SERVERLESS_ENDPOINT, and TIDBCLOUD_IAM_ENDPOINT override the API endpoints. Use absolute HTTPS URLs for hosts you trust; custom hosts and ports are supported. API redirects must stay on HTTPS with the same hostname and effective port (443 by default). Local mock APIs must use HTTPS with a certificate trusted by the provider process.
If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).
- Clone the repository
git clone git@github.com:tidbcloud/terraform-provider-tidbcloud- Enter the repository directory
cd terraform-provider-tidbcloud- Build the provider using the Go
installcommand. This will build the provider and put the provider binary in the$GOPATH/bindirectory.
go installrun go generate
see here for more detail.
I will introduce how to debug with Terraform CLI development overrides. About other ways to debug the provider, see terraform official doc for more detail
Development overrides is a method of using a specified local filesystem Terraform provider binary with Terraform CLI, such as one locally built with updated code, rather than a released binary.
- create
.terraformrcin your operating system user directory
provider_installation {
dev_overrides {
"tidbcloud/tidbcloud" = "<put your $GOPATH/bin here>"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
- run go install in the terraform-provider-tidbcloud, you will find the
terraform-provider-tidbcloudwill be installed under the$GOPATH/bin
go install
- Terraform CLI commands, such as terraform apply, will now use the specified provider binary if you follow the below config:
terraform {
required_providers {
tidbcloud = {
source = "tidbcloud/tidbcloud"
}
}
}
Twitter @PingCAP
terraform-provider-tidbcloud is under the Apache 2.0 license. See the LICENSE file for details.
