Skip to content

Latest commit

 

History

History
130 lines (89 loc) · 4.31 KB

terraform-get-tidbcloud-provider.md

File metadata and controls

130 lines (89 loc) · 4.31 KB
title summary
Get TiDB Cloud Terraform Provider
Learn how to get TiDB Cloud Terraform Provider.

Get TiDB Cloud Terraform Provider

You will learn how to get TiDB Cloud Terraform Provider in this document.

Prerequisites

Make sure that the requirements in TiDB Cloud Terraform Provider Overview are met.

Step 1. Install Terraform

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.

  1. Install the HashiCorp tap, a repository with all the required Homebrew packages.

    brew tap hashicorp/tap
  2. Install Terraform with hashicorp/tap/terraform.

    brew install hashicorp/tap/terraform

For other operating systems, see Terraform documentation for instructions.

Step 2. Create an API key

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.

Step 3. Download TiDB Cloud Terraform Provider

  1. Create a main.tf file:

    terraform {
      required_providers {
        tidbcloud = {
          source = "tidbcloud/tidbcloud"
          version = "~> 0.3.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.
  2. 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.
    

Step 4. Configure TiDB Cloud Terraform Provider with the API key

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.

Step 5. Configure TiDB Cloud Terraform Provider with sync configuration

Terraform provider (>= 0.3.0) supports an optional parameter sync.

By setting sync to true, you can create, update, or delete resources synchronously. Here is an example:

provider "tidbcloud" {
  public_key = "your_public_key"
  private_key = "your_private_key"
  sync = true
}

Setting sync to true is recommended, but note that sync currently only works with the cluster resource. If you need synchronous operations for other resources, contact TiDB Cloud Support.

Next step

Get started by managing a cluster with the cluster resource.