Introduction
The most common ways of managing the variable values in a Terraform Cloud/Enterprise workspace are by either configuring them in the workspace variables section or providing a Terraform variable definition file named *.auto.tfvars
file together with the Terraform configuration. Using the latter method will result in applying the variable values from the file in all workspaces that use this Terraform configuration (e.g. if there are multiple workspaces connected to the same VCS repository).
Use Case
In some use cases, users may want to have several Terraform variable definition files together with the Terraform configuration and have the Terraform Cloud/Enterprise workspaces each use a different variable definition file.
Procedure
-
Have a Terraform variable definition file(s) that are not named like
*.auto.tfvars
together with the Terraform configuration uploaded to the Terraform Cloud/Enterprise workspace(s) e.g. have the file(s) committed to the VCS repository connected to the workspace(s). -
Go to the Terraform Cloud/Enterprise workspace Variables section.
-
Add a new environment variable named
TF_CLI_ARGS_plan
with value-var-file="myfile.tfvars"
. Replacemyfile.tfvars
with the path of the variable definition file relative to the working directory configured for the Terraform Cloud/Enterprise workspace.
Additional Information
-
Specifying command-line arguments for the Terraform CLI via environment variables.
- Managing variables in Terraform Cloud