Test config with tuple
output value results in a panic #310
Closed
Description
terraform-plugin-testing version
v1.7.0
Actual Behavior
The following test causes a panic when the testing framework attempts to shim the output from terraform show -json
func TestRecreateTuplePanic(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"framework": providerserver.NewProtocol6WithError(New()),
},
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = [true, "hello tuple!"]
}`,
},
},
})
}
Terraform State JSON output
{
"format_version": "1.0",
"terraform_version": "1.8.0",
"values": {
"outputs": {
"test": {
"sensitive": false,
"value": [
true,
"hello tuple!"
],
"type": [
"tuple",
[
"bool",
"string"
]
]
}
},
"root_module": {}
}
}
Relevant stack trace
2024-03-22T15:19:40.253-0400 [TRACE] sdk.helper_resource: Called Terraform CLI show command for JSON state: test_working_directory=/var/folders/t8/1tjpvj_d24x8yl0st5qswzf80000gp/T/plugintest66285806 test_step_number=1 test_name=TestRecreateTuplePanic test_terraform_path=/usr/local/bin/terraform
--- FAIL: TestRecreateTuplePanic (0.38s)
panic: interface conversion: interface {} is string, not bool [recovered]
panic: interface conversion: interface {} is string, not bool
goroutine 35 [running]:
testing.tRunner.func1.2({0x105248400, 0x1400064aed0})
/opt/homebrew/Cellar/go/1.22.0/libexec/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.22.0/libexec/src/testing/testing.go:1634 +0x33c
panic({0x105248400?, 0x1400064aed0?})
/opt/homebrew/Cellar/go/1.22.0/libexec/src/runtime/panic.go:770 +0x124
github.com/hashicorp/terraform-plugin-testing/helper/resource.shimOutputState(0x1400064a9c0)
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/state_shim.go:77 +0x574
github.com/hashicorp/terraform-plugin-testing/helper/resource.shimStateFromJson(0x140000f23c0)
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/state_shim.go:33 +0xe8
github.com/hashicorp/terraform-plugin-testing/helper/resource.getState({0x105380e90, 0x140003ac7b0}, {0x10538b4a8, 0x140001396c0}, 0x140000f2280)
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing_new.go:471 +0x50
github.com/hashicorp/terraform-plugin-testing/helper/resource.runNewTest.func1.1()
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing_new.go:71 +0x44
github.com/hashicorp/terraform-plugin-testing/helper/resource.runProviderCommand({0x105380e90, 0x140003ac7b0}, {0x10538b4a8, 0x140001396c0}, 0x140002975e8, 0x140000f2280, 0x140002997f8)
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/plugin.go:438 +0x1ddc
github.com/hashicorp/terraform-plugin-testing/helper/resource.runNewTest.func1()
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing_new.go:70 +0xc8
github.com/hashicorp/terraform-plugin-testing/helper/resource.runNewTest({0x105380e90, 0x140003ac7b0}, {0x10538b4a8, 0x140001396c0}, {0x1, 0x0, {0x0, 0x0, 0x0}, 0x0, ...}, ...)
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing_new.go:462 +0x11d0
github.com/hashicorp/terraform-plugin-testing/helper/resource.Test({0x10538b4a8, 0x140001396c0}, {0x1, 0x0, {0x0, 0x0, 0x0}, 0x0, 0x0, 0x140002adb30, ...})
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing.go:922 +0x59c
github.com/hashicorp/terraform-plugin-testing/helper/resource.UnitTest({0x10538b4a8, 0x140001396c0}, {0x1, 0x0, {0x0, 0x0, 0x0}, 0x0, 0x0, 0x140002adb30, ...})
/Users/austin.valle/go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.7.0/helper/resource/testing.go:936 +0x68
github.com/hashicorp/terraform-provider-corner/internal/framework6provider.TestRecreateTuplePanic(0x140001396c0)
/Users/austin.valle/code/terraform-provider-corner/internal/framework6provider/dynamic_function_test.go:44 +0x154
testing.tRunner(0x140001396c0, 0x1053702b8)
/opt/homebrew/Cellar/go/1.22.0/libexec/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
/opt/homebrew/Cellar/go/1.22.0/libexec/src/testing/testing.go:1742 +0x318
FAIL github.com/hashicorp/terraform-provider-corner/internal/framework6provider 0.902s
FAIL
Expected Behavior
The state shimming logic needs to be updated to support tuple values that might have different types in an array 😅
terraform-plugin-testing/helper/resource/state_shim.go
Lines 59 to 95 in b5ef730
References
- Found while adding dynamic return tests in Add dynamic resource and dynamic function parameter/return tests terraform-provider-corner#228