Problem
When using the remote backend with the Terraform CLI, attempting to pass variables directly to the terraform plan command using the -var flag results in the following error:
Error: Run variables are currently not supported
Cause
This error occurs because the legacy remote backend configuration does not support passing run variables directly from the command line. The ability to use the -var flag with remote operations was introduced in Terraform v1.1 with the cloud block for HCP Terraform cloud integration.
-
Terraform Versions below 1.1: Do not support direct usage of
-varwith theremotebackend. -
Terraform Versions 1.1 and higher: Support
-varwith remote operations when the configuration uses thecloudblock instead of theremotebackend.
Solutions
There are two primary solutions depending on your version of Terraform.
Solution 1: For Terraform Versions Below 1.1
For older versions of Terraform using the remote backend, you must define variables using a file or through the web UI.
-
Use a
.auto.tfvarsfile: Create a file namedterraform.auto.tfvarsor any file ending in.auto.tfvarsin your configuration directory. Terraform automatically loads variables from these files.Add your variable definitions to the file.
## terraform.auto.tfvars example_variable_name = "value"
- Set Workspace Variables in the UI: Define the variables directly in your HCP Terraform or Terraform Enterprise workspace. These variables are automatically available to all runs in that workspace.
After using one of these methods, run terraform plan without the -var flag.
$ terraform plan
Solution 2: For Terraform Versions 1.1 and Higher
For modern versions of Terraform, update your configuration to use the cloud block for HCP Terraform cloud integration. This configuration allows you to pass variables directly from the CLI.
Update your backend configuration.
terraform {
cloud {
organization = "your-organization"
workspaces {
name = "your-workspace"
}
}
}Once the cloud block is configured, you can use the -var flag as expected.
$ terraform plan -var="example_variable_name=value"
Additional Information
- For more details on the legacy backend, refer to the Remote Backend Documentation.