I am going to implement a Terraform Plugin SDK written in C#, but I am facing problem when debugging a Terraform plugin.
So, can someone of you tell me how I can tell Terraform to use a specific protocol version when using TF_REATTACH_PROVIDERS?? The plugin protocol version 5.3 is working, but I also would like to test it against the plugin protocol version 6.3. Sadly Terraform states that my grpc server does not implement GetProviderSchema:
Error: failed to read schema for debug_init.default in registry.terraform.io/pseudo-dynamic/debug: failed to retrieve schema from provider "registry.terraform.io/pseudo-dynamic/debug": Unsupported plugin method: The plugin.(*GRPCProvider).GetProviderSchema method is not supported by this plugin
What’s strange too is that the name in the error message is “GetProviderSchema” and not “GetSchema” because “GetProviderSchema” is the gRPC method implement in plugin protocol version 6.3, but this is the protocol version that does not seem to work.
The TF_REATTACH_PROVIDERS configuration is only intended to “connect” Terraform CLI to provider server(s), while the implementation details of the connection, once made, are managed by go-plugin in that case. Maybe a good analogy in this case is the OSI model where the reattach configuration is a detail of the transport layer and the protocol version is a detail of the application layer.
Ahh I see. Yes this analogy helps to understand the architecture, but to be honest, this does not help to solve the actual problem.
You were absolutely correct, that the client needs to know at least the handshake information to connect. This can be either the process stdout or the TF_REATTACH_PROVIDERS environment variable approach, depending on whether the plugin server is started by Terraform or not. What I didn’t know is, that my TF_REATTACH_PROVIDERS environment variable was not complete. By looking at this code line terraform-plugin-go/server.go at 31394abee4612e75fa60d30615445d126f3a1c79 · hashicorp/terraform-plugin-go · GitHub for example, we can see that the ProtocolVersion is missing. By setting it and of course switching to the gRPC implementation of protocol v6 it does work. The TF_REATTACH_PROVIDERS environment variable should look now like this (formatted for better clarity):