Introduction
The -var
option is a popular way to pass variables directly to Terraform commands like terraform plan
. But when using remote backend, you may get some error like "Run variables are currently not supported" while passing -var option in terraform plan. This is because The "remote" backend does not support setting run variables at this time. Currently the only to way to pass variables to the remote backend is by creating a '*.auto.tfvars' variables file. Additionally you can also set variables on the workspace in the web UI.
Scenario
When a user tries to use -var option in terraform plan while using remote backend.
For example:
terraform plan -var="example_variable_name=value"
Error:
Run variables are currently not supported
Things to Consider Before Using the -var
Option
-
Terraform Version:
-
Versions below 1.1 do not support direct usage of
-var
with remote backends. -
Versions 1.1 and higher introduce the cloud block, which enables the use of
-var
directly in CLI commands.
-
-
Backend Configuration:
- For remote backends, the
-var
option is not directly supported. You must rely on other methods to define variables. - For cloud block configurations, the
-var
option can be used without restrictions in Terraform CLI commands.
- For remote backends, the
-
Alternative Methods for Variable Management:
- Use
*.auto.tfvars
files: These files allow you to define variables that are automatically loaded during Terraform runs. - Set workspace variables: Define variables directly in Terraform Enterprise or Terraform Cloud for a centralized and consistent approach.
- Use
Solution:
For Terraform Versions Below 1.1
- Create a
*.auto.tfvars
file containing your variables.
Example: - Alternatively, define workspace variables in the Terraform Enterprise or Cloud UI, ensuring they are accessible during runs.
For Terraform Versions 1.1 and Higher
Leverage the cloud block to pass variables directly with the -var
option during terraform plan
.
Example Command:
This setup simplifies workflows and eliminates the need for additional variable files or workspace configurations.