Skip to main content

Building Pipelines with Terraform

The Meroxa Terraform Provider allows you to provision, modify, and destroy various objects on the Meroxa platform as code.

Meroxa Terraform Provider in VSCode

Getting Started#

If you're new to Terraform, check out the Terraform Getting Started Guide.

To get started with the Meroxa Terraform Provider, require it within your Terraform File:

terraform {  required_providers {    meroxa = {      source = "meroxa/meroxa"      version = "1.0.0"    }  }}

View the full documentation in the Terraform Registry.

Example#

Here is an example pipeline that can assist with migration from PostgreSQL to Mongo; it sets up a pipeline keep both databases in sync in real-time:

# Require Provider 
terraform {  required_providers {    meroxa = {      source = "meroxa/meroxa"      version = "1.0.0"    }  }}
# Configure Provider
provider "meroxa" {  access_token = var.access_token # optionally use MEROXA_ACCESS_TOKEN env var}
# Define Pipeline
resource "meroxa_pipeline" "pipeline" {  name = "sync-postgres-mongo"}
# Configure Postgres Resource
resource "meroxa_resource" "postgres" {  name = "my-postgres"  type = "postgres"  url  = "POSTGRES_CONNECTION_URL"}
# Configure MongoDB Resource
resource "meroxa_resource" "mongo" {  name = "my-mongo"  type = "mongodb"  url  = "MONGO_CONNECTION_URL"}
# The PostgreSQL connector will capture CDC events for # every insert, update and delete operation from a Postgres table.
resource "meroxa_connector" "source" {  name      = "from-postgres"  source_id = meroxa_resource.postgres.id  input     = "User"  pipeline_id = meroxa_pipeline.pipeline.id}
# The MongoDB connector will send data to a collection within MongoDB.
resource "meroxa_connector" "destination" {  name      = "to-mongo"  destination_id = meroxa_resource.mongo.id  input     = meroxa_connector.source.streams[0].output[0]  pipeline_id = meroxa_pipeline.pipeline.id}