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 env0 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 env0 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 env0 remote backend, and to do that you’ll need to fill in this file.

terraform {
  backend "remote" {
    hostname = "backend.api.env0.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.env0.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 env0 to execute the plan and env0 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 env0 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 env0 wrappings.

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 env0 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 env0 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 env0 remote backend, and to do that you’ll need to fill in this file.

terraform {
  backend "remote" {
    hostname = "backend.api.env0.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.env0.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 env0 to execute the plan and env0 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 env0 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 env0 wrappings.

Logo Podcast
With special guest
Andrew Brown

Schedule a technical demo. See env0 in action.

CTA Illustration