env0

Custom Flows

You can create custom flows for a template, that allow you to run whatever you want (bash, python, gcloud, ansible, cloudformation, etc.), whenever you want in the deployment process (before or after Terraform init/plan/apply, and even destroy/error).
Create a file named env0.yml to define a custom flow. env0 will use this file it is defined.

Below is an example of a custom flow which creates a more "dynamic" Terraform file, based on an environment variable value, and uses Python and Jinja before the Terraform Init (the full example of this template git repo (including the env0.yml file) is here):

version: 1

deploy:
  steps:
    terraformInit:
      before:
        - pip install --user j2cli
        - 'echo Generating "stage.auto.tfvars" for "$STAGE"'
        - j2 stage.auto.tfvars.j2 > stage.auto.tfvars
        - 'echo -e "Generated \"stage.auto.tfvars\": \n$(cat stage.auto.tfvars)"'
        - 'echo Generating "elb.tf" for "$STAGE"'
        - j2 elb.tf.j2 > elb.tf
        - 'echo -e "Generated \"elb.tf\": \n$(cat elb.tf)"'

You can include the following possible hooks in an env0.yml file:

version:
  type: number
ā€‹
deploy:
  onCompletion:
    - type: string
  onSuccess:
    - type: string
  onFailure:
    - type: string
ā€‹
  steps:
    setupVariables:
      after:
        - type: string
ā€‹
    terraformInit:
      before:
        - type: string
      after:
        - type: string
ā€‹
    terraformPlan:
      before:
        - type: string
      after:
        - type: string
ā€‹
    terraformApply:
      before:
        - type: string
      after:
        - type: string
ā€‹
    storeState:
      before:
        - type: string
      after:
        - type: string
ā€‹
    terraformOutput:
      before:
        - type: string
      after:
        - type: string
ā€‹
destroy:
  onCompletion:
    - type: string
  onSuccess:
    - type: string
  onFailure:
    - type: string
ā€‹
  steps:
    setupVariables:
      after:
        - type: string
ā€‹
    terraformInit:
      before:
        - type: string
      after:
        - type: string
ā€‹
    terraformPlan:
      before:
        - type: string
      after:
        - type: string
ā€‹
    terraformDestroy:
      before:
        - type: string
      after:
        - type: string

Handling errors

If any command in your custom flow returns a non-zero exit code, the env0 deployment will stop on a 'Failed' status. You can leverage this to perform validation - for example - asserting a certain environment variable was supplied.
In such a case, env0 will display any output from stderr as the deployment error. If no output is found in stderr, it will be shown as an "Unknown Error".

Here is an example -

version:
  type: 1
deploy:
  steps:
    setupVariables:
      after:
        - if [ -z "$MY_VAR" ]; then echo "MY_VAR must be supplied" 1>&2 && exit 1; fi

Exposed env0 System Environment Variables

env0 exposes the following environment variables for you to use:

Variable NameValue Description
ENV0_ENVIRONMENT_IDThe deployed Environment ID
ENV0_PROJECT_IDThe Project ID of the deployed Environment
ENV0_DEPLOYMENT_LOG_IDThe deployment ID
ENV0_WORKSPACE_NAMEThe Terraform Workspace name used in the Environment
ENV0_ORGANIZATION_IDYour env0 organization ID
ENV0_TEMPLATE_IDThe deployed Template ID
ENV0_TEMPLATE_NAMEThe deployed Template name
ENV0_ENVIRONMENT_NAMEThe deployed Template name
ENV0_ENVIRONMENT_CREATOR_NAMEThe name of the environment creator
ENV0_ENVIRONMENT_CREATOR_EMAILThe email of the environment creator
ENV0_DEPLOYER_NAMEThe name of the deployer
ENV0_DEPLOYER_EMAILThe email of the deployer
ENV0_PR_AUTHORGitHub- the username PR author.
GitLab- the username commit author.
ENV0_PR_SOURCE_BRANCHThe source branch of the PR
ENV0_PR_TARGET_BRANCHThe target branch of the PR
ENV0_COMMIT_HASHThe commit hash of deployed Environment

See this sample of using these variables in our public templates repo.

The Deployment Container

Our deployment container is based on node:12-alpine and includes the following:

IncludesVersion
Bash5.0.11(1)-release
NodeJS12.18.3
NPM6.14.6
YARN1.22.4
GIT2.24.3
Python22.7.18
Python33.8.2
pip320.2
pip218.1
AWS CLI1.18.115
Google Cloud SDK304.0.0
Azure CLI2.10.1
kubectl1.15.11
tfenv1.0.1
Terraform default version0.12.24
jqjq-master-v20191114-85-g260888d269
OpenSSL1.1.1g
Powershell7.0.3

Adding additional binaries to the container

You can easily download any binary needed using the curl command in all steps. You can also place that new binary under opt folder in case you need it within your PATH.

Updated 4 days ago

Custom Flows


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.