Terraform for GCP How to create Bigtable Instance and Table

Paul Ravvich
Terraform for the Google Cloud Platform
3 min readMay 5, 2024
Terraform for GCP How to create Bigtable Instance and Table

Hi, this is Paul, and welcome to the #28 part of my Terraform guide. Today we will discuss, how to create a Cloud Big Table using the Terraform script.

Google Cloud Bigtable is a scalable, high-performance NoSQL database designed for processing large volumes of data with minimal latency. It is an excellent solution for applications that require real-time analysis of massive data sets.

Add Role for Service Account

First, to create a Cloud Big Table you need to add a Role Bigtable Administrator to you're Service Account. How to add permissions we already discussed in this article:

Description of the google_bigtable_instance Resource

This Terraform block describes the creation of a Bigtable instance in GCP:

resource "google_bigtable_instance" "demo_instance" {
name = "demo-instance"
deletion_protection = false
labels = {
"env": "demo"
}
cluster {
cluster_id = "demo-instance-1"
num_nodes = 1
storage_type = "SSD"
}
}

Instance Parameters:

  • name: The unique name of the Bigtable instance. Here, the instance name is set to “demo-instance”.
  • deletion_protection: A flag for deletion protection. If set to false, the instance can be deleted without additional confirmations.
  • labels: Key-value pairs for annotating the instance with additional information. Here, the instance is labeled as part of the “demo” environment.

Cluster Parameters in the Instance:

  • cluster_id: The identifier of the cluster within the instance. In the example, it is “demo-instance-1”.
  • num_nodes: The number of nodes in the cluster. Here it is set to 1, suitable for testing or development purposes.
  • storage_type: The type of storage for the cluster’s data. Possible values include “HDD” and “SSD”. “SSD” offers better performance.

Description of the google_bigtable_table Resource

Next, we create a table within our instance:

resource "google_bigtable_table" "demo_table" {
name = "demo-table"
instance_name = google_bigtable_instance.demo_instance.name
}

Table Parameters:

  • name: The name of the table within Bigtable, here “demo-table”.
  • instance_name: The name of the Bigtable instance to which the table belongs. In this case, we reference the name of the instance created above through ${google_bigtable_instance.demo_instance.name}, ensuring dependency between the resources.

Full code:

resource "google_bigtable_instance" "demo_instance" {
name = "demo-instance"
deletion_protection = false
labels = {
"env": "demo"
}
cluster {
cluster_id = "demo-instance-1"
num_nodes = 1
storage_type = "SSD"
}
}

resource "google_bigtable_table" "demo_table" {
name = "demo-table"
instance_name = google_bigtable_instance.demo_instance.name
}

Conclusion

Using Terraform to manage Bigtable in GCP provides convenience, efficiency, and the ability to version infrastructure. It enables developers and system administrators to efficiently scale applications while maintaining configuration strictness and control. Managing resources in code helps minimize errors and accelerates the deployment of new applications or services.

Thank you for reading until the end. Before you go:

Paul Ravvich

--

--

Paul Ravvich
Terraform for the Google Cloud Platform

Software Engineer with over 10 years of XP. Join me for tips on Programming, System Design, and productivity in tech! New articles every Tuesday and Thursday!