title | summary |
---|---|
Get TiDB Cloud Terraform Provider |
Learn how to get TiDB Cloud Terraform Provider. |
You will learn how to get TiDB Cloud Terraform Provider in this document.
Make sure that the requirements in TiDB Cloud Terraform Provider Overview are met.
TiDB Cloud Terraform Provider has been released to Terraform Registry. All you need to do is install Terraform (>=1.0).
For macOS, you can install Terraform with Homebrew according to the following steps.
-
Install the HashiCorp tap, a repository with all the required Homebrew packages.
brew tap hashicorp/tap
-
Install Terraform with
hashicorp/tap/terraform
.brew install hashicorp/tap/terraform
For other operating systems, see Terraform documentation for instructions.
TiDB Cloud API uses HTTP Digest Authentication. It protects your private key from being sent over the network.
Currently, TiDB Cloud Terraform Provider does not support managing API keys. So you need to create an API key in the TiDB Cloud console.
For detailed steps, see TiDB Cloud API documentation.
-
Create a
main.tf
file:terraform { required_providers { tidbcloud = { source = "tidbcloud/tidbcloud" version = "~> 0.1.0" } } required_version = ">= 1.0.0" }
- The
source
attribute specifies the target Terraform provider to be downloaded from Terraform Registry. - The
version
attribute is optional, which specifies the version of the Terraform provider. If it is not specified, the latest provider version is used by default. - The
required_version
is optional, which specifies the version of Terraform. If it is not specified, the latest Terraform version is used by default.
- The
-
Run the
terraform init
command to download TiDB Cloud Terraform Provider from Terraform Registry.$ terraform init Initializing the backend... Initializing provider plugins... - Reusing previous version of tidbcloud/tidbcloud from the dependency lock file - Using previously-installed tidbcloud/tidbcloud v0.1.0 Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
You can configure the main.tf
file as follows:
terraform {
required_providers {
tidbcloud = {
source = "tidbcloud/tidbcloud"
}
}
}
provider "tidbcloud" {
public_key = "your_public_key"
private_key = "your_private_key"
}
public_key
and private_key
are the API key's public key and private key. You can also pass them through the environment variables:
export TIDBCLOUD_PUBLIC_KEY = ${public_key}
export TIDBCLOUD_PRIVATE_KEY = ${private_key}
Now, you can use the TiDB Cloud Terraform Provider.
Get started by managing a cluster with the cluster resource.