-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to attach debugger to provider #20466
Comments
I've tried your approach with script, grep etc. However, it seems that terraform is spawning multiple instances of terraform provider binary. How did you overcome that? @joshuarowe-salesforce |
A while back the team responsible for the provider development experience implemented some features related to debugging, including support for "Debugger-based Debugging". It ended up being a more SDK/framework-heavy feature than a Terraform CLI/Core feature because it requires cooperation with the plugin to be able to start up enough to complete the plugin handshake while still giving the opportunity to add breakpoints, etc. The Terraform CLI/Core part of it is just the Thanks for this request, and sorry that we apparently missed it while announcing the introduction of debugger support! |
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. |
Current Terraform Version
Use-cases
When developing a terraform provider, sometimes the easiest way to understand the behavior of the provider is to attach a debugger to it. Unfortunately, the Terraform model of executing providers makes this a bit difficult.
Attempted Solutions
I started by replacing my provider with a shell script that invoked "dlv" in a headless mode. I then found I needed to filter output from dlv itself. This is ok, though it would've been simpler if Terraform just looked for lines beginning with a particular prefix on stdout. A little "grep" magic and this works.
While actually debugging the provider, terraform's use of the go-plugin library enables a keepalive function that causes terraform to quit while in the middle of debugging. This can be disabled in the source code by editing mux.go's DefaultConfig() routine and recompiling. This works, but isn't ideal.
Proposal
I propose either a "-debug", "-run-in-debugger", or an environment variable to the Terraform .exe. This flag should ultimately control the parameters passed to mux.Client(...). I also propose shipping a script that executes dlv that can be used in place of an actual provider; "ln -s" the script to the provider name suffices.
The call chain to mux.Client is a bit vexing in its cross-project-ness and the need to maintain compatibility, especially since . I recommend one of these approaches:
I recommend approach 4 or 5. I am coding 5, using an extra "ConnectionConfig" struct and field in the ClientConfig object.
References
See related tickets:
#16305
The text was updated successfully, but these errors were encountered: