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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes
  • Your Terraform Monolith Isn't Too Big. It's Tightly Coupled.
  • Inside terraform-provider-archive: A Memory Pattern From 2016 That Scales With Your Lambdas
  • LocalStack and Terraform: A Clean Local AWS Setup Guide

Trending

  • Java 8 Optional - Avoid Null and NullPointerException Altogether - and Keep It Pretty
  • Who Should Grade Your AI? Rules vs LLM Judges vs Humans
  • Replay, Scheduling, and Throttling: Engineering a Self-Service Kafka Streaming Tool at Scale
  • Putting Guardrails Around What Your AI Agent Is Allowed to Touch

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
DZone Core CORE ·
Jun. 29, 23 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes
  • Your Terraform Monolith Isn't Too Big. It's Tightly Coupled.
  • Inside terraform-provider-archive: A Memory Pattern From 2016 That Scales With Your Lambdas
  • LocalStack and Terraform: A Clean Local AWS Setup Guide

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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