DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • Terraform Type Constraints: Best Practices for Enterprise-Scale AWS
  • Infrastructure as Code: How Automation Evolved to Power AI Workloads
  • Discover Hidden Patterns with Intelligent K-Means Clustering

Trending

  • Why Stable RAG Answers Can Still Hide Unstable Evidence
  • Identity in Action
  • Building a Zero-Cost Approval Workflow With AWS Lambda Durable Functions
  • Building AI-Powered Java Applications With Jakarta EE and LangChain4j
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How To Use Terraform to Provision and Configure Distributed YugabyteDB Clusters

How To Use Terraform to Provision and Configure Distributed YugabyteDB Clusters

In this tutorial, explore how to use Terraform to effectively provision and configure distributed YugabyteDB Managed clusters.

By 
Denis Magda user avatar
Denis Magda
DZone Core CORE ·
Jun. 29, 23 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
6.1K Views

Join the DZone community and get the full member experience.

Join For Free

Terraform is a popular Infrastructure as Code tool that simplifies the process of creating, managing, and updating infrastructure components. In this blog post, I’ll explore how to use Terraform to effectively provision and configure distributed YugabyteDB Managed clusters.

I will guide you through the process of configuring the YugabyteDB Managed Terraform provider, defining variables, initializing the Terraform project, and adjusting configurations as needed. Let's dive in!

Steps to Configure YugabyteDB Clusters With Terraform

Before we begin, ensure you have:

  1. Access to a YugabyteDB Managed account
  2. Terraform CLI installed on your local machine

Step 1: Configure YugabyteDB Managed Terraform Provider and Authentication Token

To use YugabyteDB Managed Clusters in Terraform, we must first configure the YugabyteDB Managed Terraform provider using an authentication token.

You can create an authentication token using the YugabyteDB Managed Access Control Panel. Follow the steps in the API keys documentation to generate a token.

Create API key

Once you have your token, create a file called main.tf with the following configuration:

YAML
 
terraform {
  required_providers {
    ybm = {
      source  = "yugabyte/ybm"
      version = "1.0.2"
    }
  }
}

variable "auth_token" {
  type        = string
  description = "API authentication token"
  sensitive   = true
}

provider "ybm" {
  host            = "cloud.yugabyte.com"
  use_secure_host = true
  auth_token      = var.auth_token
}


Then, create a file named terraform.tfvars to store your authentication token securely:

YAML
 
auth_token = "your-authentication-token"


Finally, initialize your Terraform project by running the following command:

Shell
 
terraform init


You should see the message below if everything is initialized correctly:

Shell
 
Initializing the backend...

Initializing provider plugins...
- Finding yugabyte/ybm versions matching "1.0.2"...
- Installing yugabyte/ybm v1.0.2...
- Installed yugabyte/ybm v1.0.2 (self-signed, key ID 0409E86E13F86B59)

Terraform has been successfully initialized!


Step 2: Provision a YugabyteDB Managed Cluster

Now that we have configured the YugabyteDB Managed Terraform provider, let's create a three-node cluster in the US-East region of the Google Cloud Platform.

Add the following configuration snippet to your main.tf file, replacing the cluster credentials with the ones you’d like to use:

YAML
 
resource "ybm_cluster" "single_region_cluster" {
  cluster_name = "my-terraform-cluster"
  cloud_type   = "GCP"
  cluster_type = "SYNCHRONOUS"
  cluster_region_info = [
    {
      region    = "us-east1"
      num_nodes = 3
    }
  ]
  cluster_tier    = "PAID"
  fault_tolerance = "ZONE"
  node_config = {
    num_cores    = 2
    disk_size_gb = 50
  }
  credentials = {
    username = "myUsername"
    password = "mySuperStrongPassword"
  }
}


After updating the configuration, apply the changes using the following command:

Shell
 
terraform apply


Your multi-zone YugabyteDB Managed cluster should be up and running within a few minutes.

Multi-zone YugabyteDB Managed cluster

Step 3: Scale Your YugabyteDB Managed Cluster

Scaling the cluster (both horizontally and vertically) is a breeze with the YugabyteDB Terraform provider. Let's look at how you can scale the cluster to six nodes and provision more CPUs and disk space for each node instance.

To begin, update your main.tf file by changing the cluster_region_info.num_nodes to 6 nodes, node_config.num_cores to 4 CPUs, and node_config.disk_size_gb to 100GBs:

YAML
 
resource "ybm_cluster" "single_region_cluster" {
  # ...
  cluster_region_info = [
    {
      # ...
      num_nodes = 6
    }
  ]
  # ...
  node_config = {
    num_cores    = 4
    disk_size_gb = 100
  }
  # ...
}


After updating the configuration, apply the changes again:

Shell
 
terraform apply


Your six-node cluster with more CPUs and storage per instance will be upgraded and ready in just a few minutes. Note: the infrastructure upgrade happens as a rolling upgrade, without impacting your applications.

Six-node cluster with more CPUs and storage per instance

In Conclusion

This short guide shows how easy it is to use Terraform to provision and manage distributed YugabyteDB Clusters. With just a few configuration changes, we can configure the YugabyteDB Managed Terraform provider, set up a three-node cluster in the US-East region of the Google Cloud Platform, and scale the cluster to six nodes while adjusting for the increased load. 

To find out more about YugabyteDB Managed Terraform provider, you can check the technical documentation.

YugabyteDB clusters Terraform (software)

Opinions expressed by DZone contributors are their own.

Related

  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • Terraform Type Constraints: Best Practices for Enterprise-Scale AWS
  • Infrastructure as Code: How Automation Evolved to Power AI Workloads
  • Discover Hidden Patterns with Intelligent K-Means Clustering

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook