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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Terraform Drift Detection at Scale: How to Catch Configuration Drift Early
  • Codify Your Cloud and Kubernetes With Crossplane and IaC
  • Terraform State File: Key Challenges and Solutions
  • Implement Amazon S3 Cross-Region Replication With Terraform

Trending

  • Cloud Security and Privacy: Best Practices to Mitigate the Risks
  • Designing a Java Connector for Software Integrations
  • Unit Testing Large Codebases: Principles, Practices, and C++ Examples
  • Event-Driven Microservices: How Kafka and RabbitMQ Power Scalable Systems
  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
5.8K 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

  • Terraform Drift Detection at Scale: How to Catch Configuration Drift Early
  • Codify Your Cloud and Kubernetes With Crossplane and IaC
  • Terraform State File: Key Challenges and Solutions
  • Implement Amazon S3 Cross-Region Replication With Terraform

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!