Why env0
Solutions
Infrastructure as Code (IaC) Automation Teams and GovernanceManaged Self-Service env0 for the Enterprise
DocumentationPricing
Resources
Case StudiesIn the NewsVideosWebinars
Blog
Login
Get a Demo
FREE TRIALContact us
Feb 8, 2023

How to use Terraform locally with the env0 platform

Eran Elbaz
Product Marketing

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.

‍

Interested in learning more about env0?
Request a Demo
SHARE
You may also like
Day 0 Environment Creation
Share outputs between IaC stacks
Chris' Corner - March 2023
Go back to blog
CNCF Member Badge
Company
About UsIn the NewsPress ReleasesCase StudiesAdditional ResourcesCareers
Developer and DevOps
APITerraform ProviderTerratag Open Source
Terraform Cloud AlternativeDIY AlternativeAtlantis Alternative
FREE TRIAL
Follow Us
Terms of ServicePrivacy PolicySecuritySystem Status
© Copyright env0 2023
This website uses cookies. We use cookies to ensure that we give you the best experience on our website. Learn More
PreferencesDenyAccept
Privacy Preference Center
When you visit websites, they may store or retrieve data in your browser. This storage is often necessary for the basic functionality of the website. The storage may be used for marketing, analytics, and personalization of the site, such as storing your preferences. Privacy is important to us, so you have the option of disabling certain types of storage that may not be necessary for the basic functioning of the website. Blocking categories may impact your experience on the website.
Reject all cookiesAllow all cookies
Manage Consent Preferences by Category
Essential
Always Active
These items are required to enable basic website functionality.
Marketing
These items are used to deliver advertising that is more relevant to you and your interests. They may also be used to limit the number of times you see an advertisement and measure the effectiveness of advertising campaigns. Advertising networks usually place them with the website operator’s permission.
Personalization
These items allow the website to remember choices you make (such as your user name, language, or the region you are in) and provide enhanced, more personal features. For example, a website may provide you with local weather reports or traffic news by storing data about your current location.
Analytics
These items help the website operator understand how its website performs, how visitors interact with the site, and whether there may be technical issues. This storage type usually doesn’t collect information that identifies a visitor.
Confirm my preferences and close