Skip to main content

Manage Momento Caches with Terraform

Terraform is an infrastructure-as-code tool for building, changing, and versioning infrastructure safely and efficiently.

The Momento Terraform Provider allows you to create and delete Momento Caches in your Terraform project.

In this tutorial, we will walk through a basic Terraform project that creates and deletes a cache called "example".

Prerequisites

Example Terraform Project

Create a main.tf file with the following contents:

terraform {
required_providers {
momento = {
source = "momentohq/momento"
}
}
}

provider "momento" {}

resource "momento_cache" "example" {
name = "example"
}

To provide your Momento API key, you can include it in the provider block like so:

provider "momento" {
api_key = "your-api-key"
}

Or you can set an environment variable:

export MOMENTO_API_KEY="your-api-key"

Run the following commands to create and delete a Momento Cache named "example":

# Install the Momento provider from the Terraform Registry
terraform init

# Create the cache
terraform apply

# Delete the cache
terraform destroy