> ## Documentation Index
> Fetch the complete documentation index at: https://docs.envzero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Environment Outputs

> Export and share environment outputs like VPC IDs and endpoints across env zero environments as input variables for Terraform, Pulumi, and CloudFormation.

Environment Outputs let you export data generated by **OpenTofu/Terraform/Terragrunt/Pulumi/CloudFormation** environments and use it as input variables in other environments. This is useful for sharing configuration values like VPC IDs, database endpoints, or security group IDs across your infrastructure.

<Info>
  **Environment Outputs Consumers**

  Any environment - no matter the IaC type - can consume environment outputs.

  The list above names which IaC framework environment outputs can be exported.
</Info>

<Warning>
  Self-Hosted Agent Support

  * Environment Outputs are ***not*** supported for self hosted agents prior to version `3.0.724`
  * Re-installation of the agent necessitates using the **same** encryption key: `environmentOutputEncryptionKey`(see below for details)
  * **Outputs between different agents** can be supported by using the **same** `environmentOutputEncryptionKey`
  * Outputs between Self-hosted agents and SaaS agent are not supported.
</Warning>

## Environment Outputs Activation

To activate exporting Environment Outputs, a Project Admin must enable this feature within the project settings. This action necessitates opting in, signifying acknowledgment that env zero will store encrypted sensitive outputs on its platform. To opt in, navigate to the **Policies** tab within the project settings and locate the **Environment Outputs** checkbox.

<Note>
  Note

  Environment Outputs are not consumable right after enabling the **Environment Outputs** policy.

  For an Environment's Outputs to be consumable, it needs to be deployed at least once after the policy is enabled.
</Note>

### Self-Hosted Agents Activation

When employing a self-hosted agent, sensitive outputs undergo encryption using a key independent of env zero ownership. This approach ensures end-to-end encryption of sensitive values, thereby bolstering security measures to their fullest extent.

The encryption key should be provided by the `environmentOutputEncryptionKey` helm value. See our [Self-Hosted Agent - optional configuration](/guides/admin-guide/self-hosted-kubernetes-agent/custom-optional-configuration) for how to configure your agent.

## Access Restriction

env zero supports restricting access to Environment Outputs, each Environment can configure which Projects can access its outputs inside the "Settings" Tab.

If you don't want any access restrictions - select the "All environments in the organization" option.

<img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/b08a213-image.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=fe1fa2fb2be3fd38f6d34dea4488b00f" alt="Environment Outputs access restriction settings showing project selection options" width="1426" height="484" data-path="images/guides/admin-guide/variables/b08a213-image.png" />

By default, the outputs of every Environment are accessible to all Environments inside your organization until configured otherwise.

## Using Environment Outputs

Environment Outputs are accessible as inputs for other environments. To use this functionality, add a variable of type "Environment Output," following the example below:

<Frame caption="Environment Outputs Variable Selection">
  <img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/environment_outputs_variable_selection.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=f20b1be0f8319cdfb02b4184f57413d0" alt="Environment Outputs Variable Selection" width="1423" height="541" data-path="images/guides/admin-guide/variables/environment_outputs_variable_selection.png" />
</Frame>

<Info>
  **Good to Know**

  * To utilize an output of an environment, the environment must be deployed initially for env zero to capture and store the output. In workflows, you can use the free-type option to specify output names for sub-environments that haven't been deployed yet. See [Using in Workflows](#using-in-workflows) below.
  * Environment Output variables are exclusively accessible within Environment and Project scopes.
  * Only **strings** are supported at this time. See the example below for working with maps and lists.
</Info>

After adding the new variable to the list, you can select the relevant Environment Output by clicking the edit (pencil) button and selecting the relevant Environment/Sub-Environment Alias and Output Name:

<Frame caption="The value of an Environment Output Variable">
  <img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/the_value_of_an_environment_output_variable.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=dd56adbbb9377bfd6a20ce7e6aab45e5" alt="The value of an Environment Output Variable" width="1404" height="138" data-path="images/guides/admin-guide/variables/the_value_of_an_environment_output_variable.png" />
</Frame>

### Outputting Complex Types in Terraform

Currently, **only string variable types are supported by Environment Outputs**. This is partially to ensure interoperability between other frameworks (such as passing a TF variable to an Helm chart).  So if your terraform code is outputting a map or a list, use `jsonencode()`to first convert the value to a string format. See example:

```hcl theme={null}
locals {
  tags = {"foo": "bar"}
}

# instead of this
# output "tags" {
#   value = local.tags
# }

# do this
output "tags" {
  value = jsonencode(local.tags)
}
```

<Info>
  **No changes needed on the input variable`type=list() or map()`**

  Since Terraform allows input variables to be defined as strings with the proper JSON format, you don't need to make any additional changes to your input definition.
</Info>

### Using in Workflows

Environment Outputs are especially useful in [Workflows](/guides/admin-guide/workflows) for passing data between sub-environments. For example, a networking stack can output a VPC ID that a compute stack consumes as an input variable.

There are two ways to configure output-to-variable mappings in workflows:

#### Configuring at the Template Level (Recommended)

For reusable workflows and self-service scenarios, configure Environment Output variables directly on the workflow template. This pre-configures the mappings so end-users deploying the workflow do not need to set anything up.

For step-by-step instructions, see [Passing Outputs Between Sub-Environments](/guides/admin-guide/variables/workflow-variables#passing-outputs-between-sub-environments).

#### Configuring at Deploy Time

You can also configure output-to-variable mappings on the workflow deploy page:

<Steps>
  <Step title="Select the Sub-Environment">
    On the workflow deploy page, select the sub-environment that needs to **receive** the output.

    <img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/9457df8-image.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=63cbbb4429ff5002cefa855139fcc208" alt="Workflow deploy page with sub-environment selector for configuring variable inputs" width="1422" height="214" data-path="images/guides/admin-guide/variables/9457df8-image.png" />
  </Step>

  <Step title="Add an Environment Output Variable">
    In the **Variables** section, add a new variable of type **Environment Output** (same as described above).
  </Step>

  <Step title="Select the Output Source">
    Click the edit button. In the modal, you will see a **Sub-Environment Aliases** section listing the aliases from your workflow file. Select the source sub-environment.

    <img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/e8de86b-image.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=dcc2c08b22ab3cf7ae80b7617465838d" alt="Sub-Environment Aliases modal showing source sub-environment selection for environment output" width="518" height="376" data-path="images/guides/admin-guide/variables/e8de86b-image.png" />
  </Step>

  <Step title="Select or Type the Output Name">
    Select an output from the dropdown. If the source sub-environment has never been deployed, you can free-type the expected output name.

    <img src="https://mintcdn.com/envzero-b61043c8/noVHY1C-wdNQ4iZn/images/guides/admin-guide/variables/8483581-image.png?fit=max&auto=format&n=noVHY1C-wdNQ4iZn&q=85&s=f1eb6465b463a071f502e85eb37a0abb" alt="Output name dropdown with available outputs from the selected source sub-environment" width="511" height="372" data-path="images/guides/admin-guide/variables/8483581-image.png" />
  </Step>

  <Step title="Save and Deploy">
    Click **Save** and continue with the deployment.
  </Step>
</Steps>

<Note>
  On the first deployment of a workflow, outputs from sub-environments that haven't been deployed yet won't appear in the dropdown. Use the free-type option to enter the expected output name. env zero resolves outputs in dependency order based on the `needs` configuration in your workflow file.
</Note>

## Next steps

* [Managing Workflow Variables](/guides/admin-guide/variables/workflow-variables) - Configure output-to-variable mappings at the workflow template level.
* [Configuring State Access Control](/guides/admin-guide/remote-backend/state-access-control) - Control which projects can access an environment's remote state.
* [Workflow Overview](/guides/admin-guide/workflows) - Learn how workflows pass data between dependent sub-environments.
