Integrate Terraform with Tiger Cloud
Provision and manage your infrastructure as code with predictable deployments
Terraform is an infrastructure-as-code tool that enables you to safely and predictably provision and manage infrastructure.
This page explains how to configure Terraform to manage your Tiger Cloud service or self-hosted TimescaleDB.
Prerequisites
Section titled “Prerequisites”To follow the procedure on this page you need to:
-
Create a target Tiger Cloud service.
This procedure also works for self-hosted TimescaleDB.
- Download and install Terraform.
Configure Terraform
Section titled “Configure Terraform”Configure Terraform based on your deployment type:
You use the Tiger Data Terraform provider to manage Tiger Cloud services:
-
Configure Tiger Data Terraform provider
-
Create a
main.tfconfiguration file with at least the following content. Changex.y.zto the latest version of the provider.terraform {required_providers {timescale = {source = "timescale/timescale"version = "x.y.z"}}}# Authenticate using client credentials generated in Tiger Cloud Console.# When required, these credentials will change to a short-lived JWT to do the calls.provider "timescale" {project_id = var.ts_project_idaccess_key = var.ts_access_keysecret_key = var.ts_secret_key}variable "ts_project_id" {type = string}variable "ts_access_key" {type = string}variable "ts_secret_key" {type = string} -
Create a
terraform.tfvarsfile in the same directory as yourmain.tfto pass in the variable values:export TF_VAR_ts_project_id="<your-timescale-project-id>"export TF_VAR_ts_access_key="<your-timescale-access-key>"export TF_VAR_ts_secret_key="<your-timescale-secret-key>"
-
-
Add your resources
Add your Tiger Cloud services or VPC connections to the
main.tfconfiguration file. For example:resource "timescale_service" "test" {name = "test-service"milli_cpu = 500memory_gb = 2region_code = "us-east-1"enable_ha_replica = falsetimeouts = {create = "30m"}}resource "timescale_vpc" "vpc" {cidr = "10.10.0.0/16"name = "test-vpc"region_code = "us-east-1"}
You can now manage your resources with Terraform. See more about available resources and data sources.
You use the cyrilgdn/postgresql PostgreSQL provider to connect to your self-hosted TimescaleDB instance.
Create a main.tf configuration file with the following content, using your connection details:
terraform { required_providers { postgresql = { source = "cyrilgdn/postgresql" version = ">= 1.15.0" } } }
provider "postgresql" { host = "your-timescaledb-host" port = "your-timescaledb-port" database = "your-database-name" username = "your-username" password = "your-password" sslmode = "require" # Or "disable" if SSL isn't enabled }You can now manage your database with Terraform.