-
Notifications
You must be signed in to change notification settings - Fork 10.3k
terraform test parses all global variables instead of just what it needs #34070
Copy link
Copy link
Closed
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in codeterraform test
Description
Terraform Version
Terraform v1.6.1Terraform Configuration Files
variable "myvar_a" {
type = string
}
output "my_output" {
value = var.myvar_a
}Debug Output
│ Error: Variables not allowed
│
│ on <value for var.myvar_b> line 1:
│ (source code not available)
│
│ Variables may not be used here.
Expected Behavior
test.tftest.hcl... in progress
run "run"... pass
test.tftest.hcl... tearing down
test.tftest.hcl... pass
Success! 1 passed, 0 failed.
Actual Behavior
Testing with
Just add this as "test.tftest.hcl" to the root folder.
run "run" {
command = plan
assert {
condition = length(var.myvar_a) > 1
error_message = "Is not greater than 1"
}
}When i run a "terraform plan" or a "terraform test " while having "TF_VAR_myvar_a" set in my environment, both commands are doing the same (they succeed like expected).
When i now add TF_VAR_myvar_b (it's not declared in my main.tf file) terraform plan ignores the variable and still succeeds, while terraform test is failing with the mentioned debug output.
I think terraform test should ignore unused variables as terraform plan does, due to having multiple projects with different variables and secrets set via environment variables.
Steps to Reproduce
- Create main.tf with the content of the terraform configuration.
- Create test.tftest.hcl with the content of the tftest.hcl configuration from above.
- Add TF_VAR_myvar_a to your environment variables with any text
- Run terraform init
- Run terraform plan
- Run terraform test
- Now add TF_VAR_myvar_b to your environment with any text
- Run terraform plan
- Run terraform test <--- this produces the error
Additional Context
No response
References
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in codeterraform test