Problem
You may encounter the error below during the plan phase of a run in your workspace:
Error: No value for required variable
on XXX.tf line XX:
variable "your_variable_name_here" {
The root module input variable "your_variable_name_here" is not set, and has no default value. Use a -var or -var-file command line argument to provide a value for this variable.
Prerequisites
- You are using Terraform Cloud
- You are using Terraform Enterprise
Causes and Solutions
This error message may be caused by one of these reasons. Please see below each reason for a solution:
- You do not have the value for this variable defined in your configuration code
- If desired, edit your configuration code so that the variable is defined within it.
- You do not have an entry for this variable within the Variables section of your workspace under the Terraform category
- If desired, add an entry into the Variables section of your workspace
- You have an entry for this variable in the Variables section of your workspace, but the variable is under the Environment category
- Prepend the name of the variable with
TF_VAR_
to force terraform to recognize the variable at the environment level during runs
- Prepend the name of the variable with
- You have two entries for this variable within the Variables section of your workspace; one entry under the Environment category, and one under the Terraform category
- This pertains only to Terraform Enterprise `v202111-1` or newer
- You are encountering a known issue with the application and the only workaround, until this article is updated, is to rename one of those entries so that their key name is no longer conflicting.
- Your configuration code is within a monorepository, and the workspace this configuration code is associated to does not have the working directory set
- When viewing your workspace through the UI, go to Settings > General, then provide an appropriate value for the Terraform Working Directory field