-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Plan unable to execute with Space in key=value --> key = value #30600
Description
Putting a space between variable name and value causes a error message
F:\terraform-scripts\>terraform plan -var "length = 2"
│ Error: Value for undeclared variable
│
│ A variable named "length " was assigned on the command line, but the root module does not declare a variable of that name. To use this value, add a "variable" block to the configuration.while
F:\terraform-scripts\>terraform plan -var "length=2" -var "separator=."
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ createExecutes perfectly.
Terraform Version
Terraform v1.1.6
on windows_amd64
+ provider registry.terraform.io/hashicorp/aws v4.3.0
Terraform Configuration Files
resource "random_pet" "spacey" {
prefix = var.prefix[1]
length = var.length
separator = var.separator
}
variable "prefix" {
type = list(any)
default = ["Err", "Bugy", "meh"]
}
variable "length" {
default = "1"
}
variable "separator" {
default = "."
}
output "pet" {
value = random_pet.spacey
}Expected Behavior
on
terraform plan -var "variable1name = value1" -var "variable2name = value2"Please notice the "space" before and after "="
The plan should've executed successfully. Which it does, when spaces are removed (find the attached image and code).
Actual Behavior
The code spews confusing error , the one stated at the start of this post.
This error should be prompting to remove spaces instead of
│ Error: Value for undeclared variableSteps to Reproduce
Just regular terraform workflow.
terraform plan -var "length = 2" -var "separator = ."
#causes one two errors one for each argument
terraform plan -var "length = 2" -var "separator=."
#causes one error one for length argument
terraform plan -var "length = 2" -var "separator=."
#no space no errors. Executes
It could be any code with spaces around "=" as you assign -var values.
Additional Context
Since variable is declared. Values are ok. It's just a small-innocent mistake(?) at user's part.
I don't know if others have reported this issue, (I could be naive and posting it repeat)
Or if it qualifies as Documentation/Feature request, So here I am.
Seems like it isn't the bug/issue, from the issue#11 as it's closed.
but documents still lack and could potentially lead a beginner astray.
Please Consider updating/mentioning this into the documentation, if this issue can't be helped/resolved.
References
Input Variable Documentation
Variables Documentation
tf-helper issue #11
