apparentlymart / terraform-provider-assume

A Terraform provider for annotating unknown values with certain assumptions
Other
4 stars 1 forks source link

An otherwise normal terraform error/failure causes the assume provider to emit a stacktrace/crash. #1

Open craigmiskell-gitlab opened 1 week ago

craigmiskell-gitlab commented 1 week ago

If the assume provider is included, any error from terraform will result in a stack trace from the assume provider;

Stack trace from the terraform-provider-assume_v0.1.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x89906d]
goroutine 8 [running]:
go.rpcplugin.org/rpcplugin/internal/gopluginshim.(*controllerServer).Shutdown(0xe9c7c0?, {0x952f80?, 0xc000170998?}, 0x49ab85?)
    go.rpcplugin.org/rpcplugin@v0.3.0/internal/gopluginshim/gopluginshim.go:25 +0xd
go.rpcplugin.org/rpcplugin/internal/gopluginshim._GRPCController_Shutdown_Handler({0x952f80, 0xc000066060}, {0xad9f78, 0xc000616150}, 0xc000122400, 0x0)
    go.rpcplugin.org/rpcplugin@v0.3.0/internal/gopluginshim/gp_controller.pb.go:134 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00020ee00, {0xad9f78, 0xc0006160c0}, {0xadd9a0, 0xc000124000}, 0xc000614000, 0xc0001336e0, 0xe9c7a0, 0x0)
    google.golang.org/grpc@v1.62.0/server.go:1383 +0xdd1
google.golang.org/grpc.(*Server).handleStream(0xc00020ee00, {0xadd9a0, 0xc000124000}, 0xc000614000)
    google.golang.org/grpc@v1.62.0/server.go:1794 +0xe87
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.62.0/server.go:1027 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 57
    google.golang.org/grpc@v1.62.0/server.go:1038 +0x125
Error: The terraform-provider-assume_v0.1.0 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.
2024/10/31 01:23:00 terraform returned an exit code of 1

It can be reproduced with something as simple as:

terraform {
  required_providers {
    assume = {
      source  = "apparentlymart/assume"
      version = ">= 0.1.0"
    }
  }
}

resource "local_file" "configs" {
  filename = "/non-writable-dir/crash.txt"
  content = "crash"
}

where the local_file cannot create that directory (assuming you're not running as root).

apparentlymart commented 1 week ago

Thanks for reporting this, @craigmiskell-gitlab!

This seems to be a bug in the upstream library go.rpcplugin.org/rpcplugin, but fortunately I also maintain that library so I'll see what I can do to fix it soon and then publish a new release of this provider.

It seems like a relatively straightforward bug: this statement to instantiate the service that handles Terraform's "shutdown" request is not passing the close callback into the controllerServer instance, and so when Terraform instructs the plugin to shutdown it tries to call a nil function pointer. :man_facepalming:

(This bug presumably also affects the apparentlymart/hcl plugin, which uses the same upstream library.)

craigmiskell-gitlab commented 1 week ago

fortunately I also maintain that library

@apparentlymart Convenient! :)

Thanks for the quick response.