Working with Terraform Cloud remote backend
Disclaimer
As a default when using env0 we don't recommend to store your state in Terraform Cloud, and if using env0 we would recommend using a different remote backend.
There are a few limitations to using this setup and it's hard to maintain.
We recommend using this setup only for evaluating the env0 platform and if you are currently managing your state with Terraform Cloud.
If you are currently working with Terraform Cloud remote backend and would like to use env0 with this setup you will need to do the following:
- Local execution mode - First you need to change the workspace settings in Terraform Cloud to enable local runs, so you need to go to the
General Settings
of the workspace and change theExecution Mode
to be Local. - Generating a token for authentication - In order to authenticate to Terraform Cloud remote backend you need to generate an API token, so under the
User settings
underTokens
and create an API token. Please save the token, we will need it in the further steps. - Adding
env0.yml
- In your Terraform git repo you will need to add anenv0.yml
file in the Terraform folder and add the following code:
version: 1
deploy:
steps:
setupVariables:
after:
- printf "credentials \"app.terraform.io\" {\n token = \"${TF_CLOUD_TOKEN}\"\n}" > ~/.terraformrc
destroy:
steps:
setupVariables:
after:
- printf "credentials \"app.terraform.io\" {\n token = \"${TF_CLOUD_TOKEN}\"\n}" > ~/.terraformrc
- Adding template variables - In you env0 template you will need to add two variables:
Variable Name | Value |
---|---|
| The API token you've created in Terraform Cloud |
|
|
- Now you are ready to run your Template and the remote backend should be stored in Terraform Cloud.
Updated over 1 year ago
Did this page help you?