misleading tfvars error message: "Variables not allowed"
Terraform Version
❯ terraform -v
Terraform v0.12.23
Terraform Configuration Files
variables.tf:
variable "foo" {
type = string
}
terraform.tfvars:
foo = bar
Debug Output
https://gist.github.com/steinybot/6d6fed5c27d7eb919a1c939521d57c20
Crash Output
Expected Behavior
Running terraform plan should have read the variables from terraform.tfvars.
Actual Behavior
❯ terraform plan
Error: Variables not allowed
on terraform.tfvars line 1:
1: foo = bar
Variables may not be used here.
Error: No value for required variable
on variables.tf line 1:
1: variable "foo" {
The root module input variable "foo" is not set, and has no default value. Use
a -var or -var-file command line argument to provide a value for this
variable.
Steps to Reproduce
terraform plan
Additional Context
References
So the underlying issue is that I forgot to quote the value.
It should be:
foo = "bar"
not:
foo = bar
But this is a really terrible error message to get for this type of mistake.
Same issue experienced here as well, posting my specific error to help future googlers (my output is slightly different due to me wrapping my config with Terragrunt):
Error: Variables not allowed
on <value for var.ids> line 1:
(source code not available)
Variables may not be used here.
Below is the variable definition:
variable "ids" {
type = list(string)
}
The following produced the similar error as @steinybot
ids = "foo"
Correcting this to ids = ["foo"] fixed the error; it took a couple of hours to figure out, unfortunately.
Experiencing this too when I try to pass input a file to plan. I'd expect this to be a bit more verbose. It was failing as I had not encapsulated a variable with quotes when passing a secret variable from CI/CD.
I'm getting a similar error. I have provider "azurerm" { features {} } variable "aad_allowed_tenants" { type = list default = ["blah"] } output "tenantid" { value = var.aad_allowed_tenants[0] } If I run terraform plan on this, I get the expected output (blah).
but from commandline, I try to overwrite it using
terraform plan -var='aad_allowed_tenants=["aasdfad"]'
╷
│ Error: Variables not allowed
│
│ on
Just installed the latest version (1.0.0). same error.
hah, this is a powershell problem. If I flip to bash, using the exact same terraform.exe, it works.
I'm having problems with this using terratest. Bits of relevant code:
func TestTerraformHelloWorldExample(t *testing.T) {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples",
Upgrade: true,
VarFiles: []string{"test.tfvars"},
})
}
variable "key1" {
type = string
}
variable "key2" {
type = string
}
key1=foo
key2=bar
Truly confusing error message. Thanks for posting this issue, without it, it would of taken me a long time to figure out whats going on.
I got it by providing a list variable with following input: [name1,name2,name3] ...when its expecting: ["name1","name2","name3"]
The same also happens when you forget to put quotes around a string default value like this:
variable "foo" {
type = string
default = bar
}
I just hit this on Windows Terminal using a list variable as part of the command. Escaping the double quotes seemed to work:
terraform plan -var 'some_list=[\"blah1\", \"blah2\"\]'
I have the same problem for objects:
This is my variables.tf:
variable "smtp" {
type = object({
username = string
port = string
sender_address = string
server_name = string
})
default = {
username = ""
port = ""
sender_address = ""
server_name = ""
}
}
And then when running:
terraform plan -var-file=environments/weu-dev.tfvars "-var=smtp={"username":"hej", "port":"1234", "sender_address":"prutprut.dk", "server_name":"facebookcom"}"
I just get this:

Funny thing is when I do it with another variable, that has the same structure, I don't get this error.
variable "sql_database" {
type = object({
create_environmental = bool
optional_token = string
})
default = {
create_environmental = false
optional_token = ""
}
}
Here I just use:
terraform plan -var-file=environments/weu-dev.tfvars "-var=sql_database={"create_environmental": true, "optional_token": "1123444"}"
And it works perfectly.
I can't see what the difference is, other than the names and the fact that one of the attributes are a boolean. But otherwise they are very alike, but the first one fails, while the last one doesn't.
What am I not seeing??
I just hit this on Windows Terminal using a list variable as part of the command. Escaping the double quotes seemed to work:
terraform plan -var 'some_list=[\"blah1\", \"blah2\"\]'
this worked for me
I got the same issue by using Terraform Cloud, I have to mention that you must add "" when you add variables in Workspace variables, or it will report "Variables not allowed"! Must be very careful about adding Workspace variables.
I came across this issue in Terraform Cloud too. Turns out I needed to enclose the string in quotes. The error message is misleading!
Another +1 for issues with not putting quotes around the value in Terraform Cloud variable definition.
Just hit this when setting variables via the cloud API. Without adding the double quotes to the values I kept getting this cryptic error message. Python snippet below:
"variables": [
{"key": "VULTR_PLAN", "value": f'"{VULTR_PLAN}"'},
{"key": "VULTR_REGION", "value": f'"{VULTR_REGION}"'},
],
Just hit this as well, turns out my variable type was wrong, a simple edit of "variable type is incorrect/cannot be accepted" will be much clearer!
I am also getting the same error.
I have two terraform files
I have two terraform files
list.tf
variable "users" {
type = list
}
get_user_list.tf
output "get_user_list" {
value = var.users
}
When i am running
terraform plan -var 'users=["ankit","gaurav","kapil"]'
It throwing below error
╷
│ Error: Variables not allowed
│
│ on <value for var.users> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on <value for var.users> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on <value for var.users> line 1:
│ (source code not available)
│
│ Variables may not be used here.
╵
╷
│ Error: No value for required variable
│
│ on list.tf line 1:
│ 1: variable "users" {
│
│ The root module input variable "users" is not set, and has no default value. Use a -var or -var-file command line
│ argument to provide a value for this variable.
Same problem occurs when not putting spaces around the equals sign in tfvars file.
Fails:
name="Production"
Works:
name = "Production"