Easy fix: determineExpiryDate func can return nil but caller never checks for nil
This is a very easy fix if you know what to do when nil is returned. This throws a nasty segmentation fault as it tries to convert a nil to a string.
Stack trace
Stack trace from the terraform-provider-gitlab_v18.4.1 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1249f1f]
goroutine 162 [running]:
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider.(*gitlabProjectAccessTokenResource).modifyPlanRevoked(0xc00059f290, {0x1a2ca08, 0xc0006ea300}, 0xc00085d200?, 0xc00085c900, 0xc000450e00)
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider/resource_gitlab_project_access_token.go:409 +0x3ff
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider.(*gitlabProjectAccessTokenResource).ModifyPlan(0xc00059f290, {0x1a2ca08, 0xc0006ea300}, {{{{0x1a383a0, 0xc0006eb1d0}, {0x15371a0, 0xc0006eaf00}}, {0x1a468f8, 0xc0008a1a40}}, {{{0x1a383a0, ...}, ...}, ...}, ...}, ...)
gitlab.com/gitlab-org/terraform-provider-gitlab/internal/provider/resource_gitlab_project_access_token.go:284 +0x435
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).PlanResourceChange(0xc000358788, {0x1a2ca08, 0xc0006ea300}, 0xc000332070, 0xc0006434e0)
github.com/hashicorp/terraform-plugin-framework@v1.15.1/internal/fwserver/server_planresourcechange.go:347 +0x1ff6
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).PlanResourceChange(0xc000358788, {0x1a2ca08?, 0xc0006ea210?}, 0xc0000c6e40)
github.com/hashicorp/terraform-plugin-framework@v1.15.1/internal/proto6server/server_planresourcechange.go:72 +0x592
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).PlanResourceChange(0xc00031d180, {0x1a2ca08?, 0xc00068fec0?}, 0xc0000c6e40)
github.com/hashicorp/terraform-plugin-mux@v0.20.0/tf6muxserver/mux_server_PlanResourceChange.go:73 +0x2a2
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).PlanResourceChange(0xc000360780, {0x1a2ca08?, 0xc00068e360?}, 0xc000450400)
github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/tf6server/server.go:901 +0x3d9
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_PlanResourceChange_Handler({0x1712e80, 0xc000360780}, {0x1a2ca08, 0xc00068e360}, 0xc000450380, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:669 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002fc400, {0x1a2ca08, 0xc00068e2d0}, 0xc0000c6720, 0xc000199ad0, 0x2533690, 0x0)
google.golang.org/grpc@v1.72.1/server.go:1405 +0xfe8
google.golang.org/grpc.(*Server).handleStream(0xc0002fc400, {0x1a2d750, 0xc0001a0000}, 0xc0000c6720)
google.golang.org/grpc@v1.72.1/server.go:1815 +0xb95
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/grpc@v1.72.1/server.go:1035 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 36
google.golang.org/grpc@v1.72.1/server.go:1046 +0x11d
Error: The terraform-provider-gitlab_v18.4.1 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.
Code where the error is:
Lines 398-409 of resource_gitlab_project_access_token.go on tag v18.4.1
// Calculate new expiration date
expiryDate, err := r.determineExpiryDate(planData)
if err != nil {
resp.Diagnostics.AddError(
"Error determining new expiry date",
fmt.Sprintf("Could not determine new expiry date: %s", err),
)
return
}
// Set the planned values
planData.ExpiresAt = types.StringValue(expiryDate.String())
Edited by 🤖 GitLab Bot 🤖