Documentation

How to Deploy and Manage Redis Databases on AWS Using Terraform

Prerequisites:

  • Install Terraform on MacOS.
  • Create a free Redis Cloud account.
  • Create your first subscription.
  • Enable API

Step 1: Install Terraform on MacOS

Use Homebrew to install Terraform on MacOS as shown below:

Step 2: Sign up for a free Redis Cloud account
Sign up for a free Redis Cloud account. https://redis.com/try-free/

Step 3: Enable Redis Cloud API

If you have a Flexible (or Annual) Redis Cloud subscription, you can use a REST API to manage your subscription programmatically. The Redis Cloud REST API is available only to Flexible or Annual subscriptions. It is not supported for Fixed or Free subscriptions.

For security reasons, the Redis Cloud API is disabled by default. To enable the API:

  • 1. Sign in to your Redis Cloud subscription as an account owner.

  • 2. From the menu, choose Access Management.

  • 3. When the Access Management screen appears, select the API Keys tab

    If a Copy button appears to the right of the API account key, the API is enabled. This button copies the account key to the clipboard.

    If you see an Enable API button, select it to enable the API and generate your API account key.

    To authenticate REST API calls, you need to combine the API account key with an API user key to make API calls.

Step 4: Create a main.tf file

It’s time to create an empty “main.tf” file and start adding the provider, resource and data sources as shown below:

Step 5: Create an execution plan

The Terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. By default, when Terraform creates a plan, it reads the current state of any already existing remote objects to make sure that Terraform state is up to date. It then compares the current configuration to the prior state and then proposes a set of change actions that should make the remote object match the configuration.

Step 6: Execute the action

The Terraform apply command executes the actions proposed in a Terraform plan.

Step 7: Verify the database

You can now verify the new database created under Subscription named “db-json.”

Deploy a Redis Database with JSON and [other](Redis Stack ) features on AWS using Terraform

Step 8: Cleanup

The Terraform destroy command is a convenient way to destroy all remote objects managed by a particular Terraform configuration. While you will typically not want to destroy long-lived objects in a production environment, Terraform is sometimes used to manage ephemeral infrastructure for development purposes, in which case you can use terraform destroy’ to conveniently clean up all of those temporary objects once you are finished with your work.