Home
Blog
How to use Terraform locally with the env zero platform

How to use Terraform locally with the env zero platform

Eran Elbaz
Engineering Team
with special guest
Mitchell
Hashimoto
Mitchell Hashimoto headshot

Under pressure to use an automated IaC tool but don’t want to deal with the overhead of pushing code for every change? Here’s a step-by-step look at how to use Terraform locally and still have access to all the benefits of the envzero platform

This is a cool capability, and one I take advantage of regularly!

Deploy an environment

Start by deploying an environment with some cloud resources. Enable the envzero remote backend, and remember that when you do that you must also fill in the workspace name.

Reference Terraform

The next step is to make sure Terraform knows we’re using the envzero remote backend, and to do that you’ll need to fill in this file.

terraform {
  backend "remote" {
    hostname = "backend.api.envzero.com"
    organization = "<YOUR_ORGANIZATION_ID>"
    workspaces {
      name = "<YOUR_WORKSPACE_NAME>"
    }
  }
}

Find more details in the load variables step of our deployment. 

After that it’s time to create a personal access token.

 

Login to Terraform

Once all those steps have been completed, it will be possible to use the Terraform login command - terraform login backend.api.envzero.com - with the newly generated token.

And that’s it! 

It’s now possible to run Terraform commands from a local machine. The Terraform CLI will connect to envzero to execute the plan and envzero will also report all the logs back to the local machine. 

I find this very useful because I can continue to work from my local machine with uncommitted code, meaning my development cycles are fast and safe with all the envzero support for auditing, role-based access control, Pretty Plan and more. 

One last reminder: it’s not possible to run terraform apply locally since we believe the single source of truth is from your version control, but, if that is the preference, define the environment variable (TF_FORCE_LOCAL_BACKEND=1) and the apply will only run locally without envzero wrappings.

Schedule a technical demo
See env zero in action
Schedule demo

Related Content

All articles