Share outputs between IaC stacks

Interested in learning more about env0?

Eran Elbaz

Product Marketing

Share this post

As our codebase becomes more complex, it often becomes an issue to maintain one IaC stack for our entire deployment, and we might think of splitting our IaC stack into smaller, more manageable components, with the relevant IaC for the job. 

The question is how can we pass outputs between deployment stacks? 

For example we would like to deploy EKS using Terraform and you need the EKS details for your k8s resources, those are different kind of Infrastructure as Code products that have no native support for output sharing.

With Import Variable Plugin, you can easily fetch output variables from other environments regardless of their IaC type and use them as input variables for your current environment.

This plugin executes a script to help you fetch output variables from other environments to use as input variables for your current environment. To use this plugin, you need to set up the env0 API key and secret for the relevant organization.

To get started with the Import Variable Plugin, you can 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

Make sure to define the plugin after the setup variables step.

After configuring the custom flow above with a new or existing environment, you can add a Terraform or Environment variable. The key is the name of your variable, and the value is a reference to another environment's output variable, with the following format: [.code]${env0:<env0_environment_id>:<output_key>}[.code]. 

Then, when you run the environment, the plugin will fetch the other environment output.

For example, let's say you need the VPC ID from your "Dev VPC" environment. 

First, you need to get the [.code]ENV0_ENVIRONMENT_ID[.code] from that environment (note: the environment ID can be found in the URL or as part of the init variable step). 

Then, find the output name you want to use in the environment resources tab (e.g. vpc_id). 

The value you enter would be: [.code]${env0:<env0_environment_id>:<output_name>}[.code].

Using the Import Variable Plugin can save you time and make your Terraform code more modular and reusable. 

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

No items found.
The best way to manage your Terraform

Custom workflows let you model any process you have.

Improve collaboration so your teams are always on the same page with your Infrastructure as Code

Visualize the effect of IaC changes before and after deployment.

Eran Elbaz

Logo

The best way to manage your Terraform

Custom workflows let you model any process you have.

Improve collaboration so your teams are always on the same page with your Infrastructure as Code

Visualize the effect of IaC changes before and after deployment.

Start Free Trial
See what env0 can do for you

env0 is the best way to deploy, scale, and manage your Terraform and other Infrastructure as Code tools.

Milo waving