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.
ENV0_API_KEY
(Required)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
- Configure the Custom Flow above with a new environment or an existing environment
- Add a Terraform Variable
- The Key is the name of your Terraform variable
- The Value is a reference to another environment's output variable. With the following format:
${env0:<env0_environment_id>:<output_key>}
- Run the environment, and env0 will fetch the value
Example
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. For example, given this URL
https://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. - Find the output name you want to use in the environment resources tab. e.g.
vpc_id
- The value you enter would be:
${env0:9cec1eb6-c17f-4cca-9cdf-606a23cdf6b5:vpc_id}
Updated 8 months ago