Import Variable Plugin

Fetch output values from another environment and insert them as terraform variables.

Overview

This plugin executes a script to help you fetch output variables from other environments to use as input variables for your current environment.

For more information, check out the Import Variable Plugin git repository.

Requirements

To use this plugin, you need to setup the env0 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.

version: 2  
deploy:  
  steps:  
    setupVariables:  
      after:  
        - name: Import Variables
          use: https://github.com/env0/env0-import-variable-plugin
  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 env0 will fetch the value

Example

For example, if I needed the VPC ID from my "Dev VPC" Environment:

  1. First I need to get the ENV0_ENVIRONMENT_ID from that environment. note: the Environment ID can be found in the URL. For example, given this URLhttps://app.env0.com/p/7320dd7a-4822-426c-84b5-62ddd8be0799/environments/9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5 9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5 is the ENV0_ENVIRONMENT_ID.
  2. Find the output name you want to use in the environment resources tab. e.g. vpc_id
  3. The value you enter would be: ${env0:9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5:vpc_id}