terraform-plugin-framework
terraform-plugin-framework copied to clipboard
types/basetypes: Panic with Collection Value Type Missing ElemType
Module version
v1.3.1
Relevant provider source code
When implementing a default value, but not setting defaults.{TYPE}Response.PlanValue or diagnostics.
func (d defaultImpl) ListDefault(ctx context.Context, req defaults.ListRequest, resp *defaults.ListResponse) {
// intentionally not setting resp.PlanValue before returning
}
The easier test case is directly creating an invalid value:
basetypes.ListValue{}.ToTerraformValue(ctx)
Terraform Configuration Files
N/A
Debug Output
N/A
Expected Behavior
In the case of the default value handling, the response should be automatically populated with a valid null value by default. For other usages of invalid value types, some form of fallback "missing type" behavior over a panic, similar to #755.
Actual Behavior
--- FAIL: TestDataDefault (0.01s)
--- FAIL: TestDataDefault/list-attribute-request-path (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x30 pc=0x100a161ec]
goroutine 14 [running]:
testing.tRunner.func1.2({0x1010fe140, 0x10137c890})
/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1526 +0x1c8
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1529 +0x384
panic({0x1010fe140, 0x10137c890})
/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListValue.ToTerraformValue({{0x0, 0x0, 0x0}, {0x0, 0x0}, 0x0}, {0x101154860, 0x1400009c018})
/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_value.go:208 +0x5c
Steps to Reproduce
go test
References
None