Environment Variables
Environment variables play a crucial role in configuring and customizing Terrateam workflows and hooks. Terrateam provides a set of built-in environment variables that you can use to access information about the current workflow execution context and the results of Terrateam operations. Additionally, you can define your own custom environment variables to store and pass data between different steps and stages of your Terrateam pipelines.
Built-in Environment Variables
Terrateam provides the following built-in environment variables:
Workflow Environment Variables
Name | Description |
---|---|
TERRATEAM_PLAN_FILE | The path to the generated Terraform plan file. |
TERRATEAM_DIR | The working directory relative to the root of the repository. |
TERRATEAM_WORKSPACE | The Terraform workspace being executed against. |
TERRATEAM_ROOT | The absolute path to the root of your checked-out repository. |
Post-hook Environment Variables
Name | Description |
---|---|
TERRATEAM_RESULTS_FILE | The path to a JSON file that contains the results of all executed dirspaces. |
Expand for example TERRATEAM_RESULTS_FILE
GitHub Actions Environment Variables
In addition to the Terrateam-specific environment variables, you also have access to the default environment variables provided by GitHub Actions. Refer to the GitHub documentation for a complete list of available variables.
Custom Environment Variables
Terrateam allows you to define your own custom environment variables in your workflows and hooks. You can use custom environment variables to store and pass data between different steps, set configuration options, or provide dynamic values based on the execution context.
Defining Custom Environment Variables in Workflows
To define custom environment variables in your Terrateam workflows, you can use the env
step type. Here’s an example workflow configuration that sets a custom environment variable:
In this example, the env
step sets a custom environment variable named MY_CUSTOM_VAR
with the value “Hello, World!“. The subsequent run
step can then access the value of MY_CUSTOM_VAR
using the $
prefix.
Defining Custom Environment Variables in Hooks
Similarly, you can define custom environment variables in your Terrateam hooks using the env
hook type. Here’s an example hook configuration that sets a custom environment variable:
In this example, the env
hook in the pre
section of the plan
hook sets a custom environment variable named MY_HOOK_VAR
with the value “Hello from the pre-plan hook!“. The run
hook in the post
section can then access the value of MY_HOOK_VAR
.
Using Custom Environment Variables
Once you have defined your custom environment variables, you can use them in your Terrateam configurations and scripts by referencing them with the $
prefix followed by the variable name. For example:
In this example, the $MY_CUSTOM_VAR
variable will be expanded to the actual value of the MY_CUSTOM_VAR
environment variable during execution.
Best Practices
When using environment variables, keep the following best practices in mind:
- Use meaningful and descriptive names for your own custom environment variables to avoid conflicts with Terrateam’s built-in variables or other system variables.
- Be cautious when using environment variables to store sensitive information, such as secrets or credentials. Instead, consider using secure mechanisms like Terrateam’s integration with GitHub Secrets or a secrets management system.
- Ensure that your scripts and configurations handle missing or empty environment variables gracefully to avoid unexpected errors or behavior.