Skip to main content
Consider using Environment Outputs insteadFor most use cases, the native Environment Outputs feature is the recommended approach. It provides:
  • Native UI integration with no API keys required
  • Support for sensitive/secret outputs
  • Built-in workflow support with template-level configuration
Use this plugin if you need a code-driven / GitOps approach where output-to-variable mappings are defined in env0.yaml custom flows and version-controlled alongside your IaC code, rather than configured through the UI.You can also define Environment Output variables programmatically using the env0 Terraform Provider.

Overview

This plugin fetches output values from another environment and inserts them as Terraform and/or environment variables. The ${env0:...} and ${env0-workflow:...} syntax documented below is specific to this plugin and is not part of the native Environment Outputs feature. Similar to self hosted agent secrets, use this notation in the value of the terraform input value:
  • ${env0:<environment id>:<output name>}
  • ${env0:<environment name>:<output name>} (see note below about Environment Names restrictions)
  • ${env0-workflow:<parent node name>:<output name>}
For fetching output values that contain lists (like subnet ids) or maps (like tags), make sure you select JSON type for your input variable, and in the value use the following JSON schema.
  • {"ENV0_ENVIRONMENT_NAME":<environment name>, "output": <output name>}
  • {"ENV0_WORKFLOW_PARENT":<parent name>, "output": <output name>}
For more information, check out the Import Variable Plugin git repository.

Requirements

To use this plugin, you need to setup the env zero API key and secret for the environment. You can use an Organization API Key or a Personal API Key.
  1. ENV0_API_KEY (Required)
  2. ENV0_API_SECRET (Required)

Usage

Add the following env0.yaml custom flow file to your environment or project.
From version 0.5.0, the plugin downloads a prebuilt binary for the agent architecture (linux/amd64 or linux/arm64) and verifies its checksum. It no longer installs Go on every run. If the download fails, the plugin installs Go and builds from source, as in earlier versions. See the 0.5.0 release notes.
  • The binary version follows the plugin version in use:. For example, @0.5.1 uses the 0.5.1 binary. To select a different release binary, set the optional version input.
  • If you copied the plugin script into your env0.yaml, replace it with the use: line above. A copied script installs Go on every run.
  • Self-hosted agents need access to github.com and release-assets.githubusercontent.com to download the binary. Without this access, the plugin builds from source.
  1. Configure the Custom Flow above with a new environment or an existing environment
  2. Add a Terraform Variable
  3. The Key is the name of your Terraform variable
  4. The Value is a reference to another environment’s output variable. With the following format: ${env0:<env0_environment_id>:<output_key>}
  5. Run the environment, and env zero will fetch the value

Workflows

The workflow syntax below (${env0-workflow:...}) is specific to this plugin. If you are using the native Environment Outputs feature, you do not need this plugin or this syntax. See Passing Outputs Between Sub-Environments for the UI-based approach.
When using the plugin within a workflow you can use the following notation: string types: ${env0-workflow:<parent name>:<output name>}
json types: {"ENV0_WORKFLOW_PARENT":<parent name>, "output": <output name>}
In this case, the parent name is the yaml parent, not the “environment name.”
For example, given the following env0.workflow.yaml the variable structure to fetch the “vpc-id” from the “parent vpc” would be ${env0-workflow:vpc:vpc-id} Similarly, to fetch the tags (in json) from the vpc: {"ENV0_WORKFLOW_PARENT":vpc, "output": tags}
env0.workflow.yaml

Environment Name Restrictions

  • Environment Names must be unique, otherwise, the script just uses the “first” matching environment name.
  • Environment Names must not include spaces ” ” or slashes /. Ideally, your environment only contains alphanumeric characters and dashes -. **

Inputs

  • version (optional): The release tag of the plugin binary to use, for example 0.5.1. If you do not set it, the plugin uses the release that matches the plugin version in use:.

Example Usage

In this example we will run fetch the variable from a “Dev VPC” environment.
  1. Configure the Custom Flow above with a new environment or an existing environment
  2. Add a Terraform Variable
  3. The Key is the name of your Terraform variable
  4. The Value is a reference to another environment’s output variable. For example, if I needed the VPC ID from my “Dev VPC” Environment:
  • First I need to get the ENV0_ENVIRONMENT_ID from that environment.
    note: the Environment ID can be found in the URL: https://app.env0.com/p/7320dd7a-4822-426c-84b5-62ddd8be0799/environments/9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5 where 9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5 is the ENV0_ENVIRONMENT_ID.
  • Find the output name in the environment Resources tab. e.g., vpc_id
  • The value you enter would be then: ${env0:9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5:vpc_id}
  1. Run the environment, and env zero will fetch the value

Further Reading

This plugin takes advantage of Terraform variable precendence and *.auto.tfvars. ** If you must know why, it’s because this script is written in Bash, and I’m taking advantage of Bash arrays which doesn’t process spaces well, and also I’m saving the outputs to the filesystem which gets confused with slashes.

Next steps