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 [email protected]:tidbcloud/terraform-provider-tidbcloud.git
- Go to the examples/workflows/tidbcloud_serverless_cluster directory.
cd examples/workflows/tidbcloud_serverless_cluster
- 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
- Rename the
terraform.tfvars.templates
toterraform.tfvars
and change the variables as you wish. You can also pass them by environment variables.
export TF_VAR_password=fake_password
export TF_VAR_cluster_name=fake_cluster_name
- Execute the following commands to create a serverless tier
terraform init
terraform apply --auto-approve
- The example will output the
connection_strings
for 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.
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 [email protected]:tidbcloud/terraform-provider-tidbcloud
- Enter the repository directory
cd terraform-provider-tidbcloud
- Build the provider using the Go
install
command. This will build the provider and put the provider binary in the$GOPATH/bin
directory.
go install
run 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
.terraformrc
in 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-tidbcloud
will 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.