Panic on `random_string` when all properties set to `false`
guineveresaenger opened this issue · 3 comments
Terraform CLI and Provider Versions
Terraform v1.5.7
on darwin_arm64
- provider registry.terraform.io/hashicorp/random v3.6.0
Terraform Configuration
terraform {
required_providers {
random = {
version = "3.6.0"
}
}
}
provider "random" {
}
# Create a random string resource
resource "random_string" "my_string" {
length = 16
special = false
upper = false
number = false
lower = false
}
# Output the generated random string
output "random_string_result" {
value = random_string.my_string.result
}
Expected Behavior
I should see an error telling me my configuration is nonsensical.
Actual Behavior
I got a panic.
Steps to Reproduce
terraform apply
- See panic stack trace:
Stack trace from the terraform-provider-random_v3.6.0_x5 plugin:
panic: crypto/rand: argument to Int is <= 0
goroutine 26 [running]:
crypto/rand.Int({0x102d2e600?, 0x14000142380?}, 0xffffffffffffffff?)
crypto/rand/util.go:64 +0x29c
github.com/terraform-providers/terraform-provider-random/internal/random.generateRandomBytes(0x14000182c08, 0x10)
github.com/terraform-providers/terraform-provider-random/internal/random/string.go:90 +0xc8
github.com/terraform-providers/terraform-provider-random/internal/random.CreateString({0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, {0x0, ...}})
github.com/terraform-providers/terraform-provider-random/internal/random/string.go:67 +0x35c
github.com/terraform-providers/terraform-provider-random/internal/provider.(*stringResource).Create(0xd?, {0x102d34738, 0x14000354cf0}, {{{{0x102d38960, 0x14000355ce0}, {0x102c585e0, 0x14000355b60}}, {0x102d39b18, 0x14000136d20}}, {{{0x102d38960, ...}, ...}, ...}, ...}, ...)
github.com/terraform-providers/terraform-provider-random/internal/provider/resource_string.go:71 +0x2c8
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).CreateResource(0x1400015d600, {0x102d34738, 0x14000354cf0}, 0x14000183320, 0x140001832c0)
github.com/hashicorp/terraform-plugin-framework@v1.4.2/internal/fwserver/server_createresource.go:101 +0x430
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ApplyResourceChange(0x14000183480?, {0x102d34738, 0x14000354cf0}, 0x14000356410, 0x14000183480)
github.com/hashicorp/terraform-plugin-framework@v1.4.2/internal/fwserver/server_applyresourcechange.go:57 +0x370
github.com/hashicorp/terraform-plugin-framework/internal/proto5server.(*Server).ApplyResourceChange(0x1400015d600, {0x102d34738?, 0x14000354ba0?}, 0x14000356370)
github.com/hashicorp/terraform-plugin-framework@v1.4.2/internal/proto5server/server_applyresourcechange.go:55 +0x314
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140001e0640, {0x102d34738?, 0x140003541b0?}, 0x14000540070)
github.com/hashicorp/terraform-plugin-go@v0.19.1/tfprotov5/tf5server/server.go:859 +0x3bc
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x102d080a0?, 0x140001e0640}, {0x102d34738, 0x140003541b0}, 0x14000412080, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.19.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001de1e0, {0x102d34738, 0x140003540f0}, {0x102d38c98, 0x1400048a1a0}, 0x14000358000, 0x1400033e210, 0x10317a538, 0x0)
google.golang.org/grpc@v1.59.0/server.go:1343 +0xc6c
google.golang.org/grpc.(*Server).handleStream(0x140001de1e0, {0x102d38c98, 0x1400048a1a0}, 0x14000358000)
google.golang.org/grpc@v1.59.0/server.go:1737 +0x9f0
google.golang.org/grpc.(*Server).serveStreams.func1.1()
google.golang.org/grpc@v1.59.0/server.go:986 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/grpc@v1.59.0/server.go:997 +0x174
Error: The terraform-provider-random_v3.6.0_x5 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
How much impact is this issue causing?
Low
Logs
https://gist.github.com/guineveresaenger/79f6457a8ad86c182c9e46c589edb8bd
Additional Information
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Hi @guineveresaenger 👋
Thank you for reporting this bug.
It looks like we were both working on a fix at the same time!
I'm interested to hear the more about the use-case for assigning special
, upper
, lower
and numeric
/number
all to false at the same time. Can you provide some further context on when you are doing this and why?
hi @bendbennett! thank you for the quick fix, I'm going to close mine in favor of yours.
I'm interested to hear the more about the use-case for assigning special, upper, lower and numeric/number all to false at the same time. Can you provide some further context on when you are doing this and why?
Honestly, we were running edge case tests and this came up - this did not reflect a real-world error, which, while not impossible, would be unusual to have happen, since defaults are set to true
. Anyway, an error message is a much nicer experience than a flat out panic. Thanks again!
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.