Remote Backend

Terraform uses persisted state data to keep track of the resources it manages. Most non-trivial Terraform configurations use a backend to store the state remotely. This lets multiple people access the state data and work together on that collection of infrastructure resources.

Terraform offers several state storage options, of which env0 supports Remote Backend, which has some great benefits such as:

  • No underlying infrastructure setup and management - env0 takes care of the setup as opposed to other approaches, where you need to do all the setup and management yourself (for example, S3 Backend requires you to create an S3 Bucket and an optional DynamoDB Table for locking beforehand).
  • Security - env0 stores the state securely and assures only you can access it.
  • State consistency - Remote Backends assure that users won't overwrite each other's state with a locking mechanism and that they receive the most recent state on every Terraform operation
  • Remote plans - By providing the Remote Backend configuration and successful login, users can run terraform plan locally, which will trigger a remote plan in env0. The remote plan will use the shared state and variables set for the env0 environment.

Using env0's Remote Backend has additional advantages:

  • No Terraform Backend configuration when running inside env0 - You don't have to provide any type of configuration; just deploy your code as is, and env0 will automatically configure it to use the Remote Backend.
  • States UI - View the current version of your current state and all previous versions.
  • Correlation of Deployment to State - easily figure out which deployment is responsible for a specific change to your state (Coming soon).
  • State Access Control - Specify which environments should be able to access an environment's state in env0.

๐Ÿšง

Reusing Workspace Name

Terraform uses the workspace name to distinguish between one state and another.

When using a remote backend in env0, the workspace name identifies that environment's state.

Therefore, if a remote backend environment is created and then marked as inactive, and another remote backend environment is created with the same workspace name, it would inherit the first environment's state.

Use Remote Backend in a New Environment

Using Remote Backend in your environments is simple:

  • Create a new Environment
    • Check the Enable Remote State checkbox
    • Enter a Workspace Name

Here's what it looks like for environments based on a predefined template:

Here's what it looks like for environments based on a direct VCS integration:

That's it!

๐Ÿšง

Workspace Name Restrictions

env0 enforces that a Workspace Name must be unique among all Remote Backend environments in the Organization. The Terraform configuration for the Remote Backend consists of Organization ID and Workspace Name. Therefore, we have this limitation to block possible state conflicts.

๐Ÿ“˜

Force Remote Backend

You can force all new Terraform environments in a project to be created with a Remote Backend. See Force Remote Backend for more info.

Viewing & Downloading State Versions

After successfully deploying an environment with a Remote Backend, you would have access to the States tab on the environment page.

There you should see all the state versions, organized from latest to oldest.

To download a state version, simply hover on the desired version. A Download button should appear.

Clicking it should initiate a file download.

๐Ÿ“˜

Note

Bigger state files may take a few moments to start downloading

If the state version was created by env0 (i.e., not locally), there would also be a quick access link to its relevant deployment log.

Using the Remote Backend Locally

Please check out this guide: Using the Remote Backend on your local machine

โœ๏ธ Suggested Blog Content

Terraform Modules Guide

Terraform Plan Examples

Managing Terraform Variable Hierarchy

Manage Terraform Remote State with a Remote Backend