Skip to content

terraform test: referencing variables at testing file level results in a crash #34529

@liamcervante

Description

@liamcervante

Terraform Version

v1.7.0-rc2

Terraform Configuration Files

# main.tf

variable "input" {
    type = string
}

output "value" {
    value = var.input
} 
# main.tftest.hcl

variables {
  input = var.env_var_input
}

run "execute" {}

Debug Output

N/A

Expected Behavior

should not crash, and should be able to reference environment variable

Actual Behavior

terraform test
main.tftest.hcl... in progress

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

runtime error: invalid memory address or nil pointer dereference
goroutine 11 [running]:
runtime/debug.Stack()
        /Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
        /Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/debug/stack.go:16 +0x1c
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /Users/runner/work/terraform/terraform/internal/logging/panic.go:58 +0x164
panic({0x105df7600?, 0x107c13c30?})
        /Users/runner/hostedtoolcache/go/1.21.5/x64/src/runtime/panic.go:914 +0x218
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).GetVariables(0x14000a3def8, 0x1400017e9a0, 0x1400009d3b0, {0x0, 0x0, 0x102fc0560?})
        /Users/runner/work/terraform/terraform/internal/backend/local/test.go:1063 +0x530
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).run(0x14000a3def8, 0x1400009d3b0, 0x1400009d400, 0x1400091c370, 0x1400017e9a0)
        /Users/runner/work/terraform/terraform/internal/backend/local/test.go:405 +0x708
github.com/hashicorp/terraform/internal/backend/local.(*TestFileRunner).Test(0x14000a3def8, 0x1400009d400)
        /Users/runner/work/terraform/terraform/internal/backend/local/test.go:336 +0x48c
github.com/hashicorp/terraform/internal/backend/local.(*TestSuiteRunner).Test(0x140004c45a0)
        /Users/runner/work/terraform/terraform/internal/backend/local/test.go:140 +0x2bc
github.com/hashicorp/terraform/internal/command.(*TestCommand).Run.func1()
        /Users/runner/work/terraform/terraform/internal/command/test.go:230 +0x9c
created by github.com/hashicorp/terraform/internal/command.(*TestCommand).Run in goroutine 1
        /Users/runner/work/terraform/terraform/internal/command/test.go:224 +0xab4

Steps to Reproduce

terraform init
terraform test

Additional Context

No response

References

No response

Metadata

Metadata

Assignees

Labels

bugconfirmeda Terraform Core team member has reproduced this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions