Custom flows are an essential and important feature in the env0 platform, and today we released a new and powerful enhancement to declare environment variables that are persistent between commands and steps in the
env0.yml file, and can be used either by other Terraform/Terragrunt commands or in other custom flow commands.
env0.yml steps, append your key-value to the
$ENV0_ENV file, like so:
echo KEY=VALUE >> $ENV0_ENV. You may do so explicitly, in a separate command, or within your own script. The value can be accessed in any later step, explicitly in a command or within a script.
Using this feature you may also export Terraform environment variables. The key should use the
TF_VAR_ prefix, as mentioned in the official Terraform documentation (See this for more details)
When declaring an environment variable in deploy, it won't be recognized in destroy and vice versa.
Check out this example template that demonstrates the use of TF_VAR and $ENV0_ENV.
You can read more about this feature in our official docs: https://docs.env0.com/docs/custom-flows#exporting-your-own-environment-variables
This feature is also available in our Self hosted as agent in version >= v3.0.33.