-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Can't debug github.com/hashicorp/terraform #496
Comments
Terraform uses plugins by executing them via shell. The plugins are different running processes than what binary you are launching. As such you need either to attach to the new process or execute the plugins with delve |
@sodre If you compile |
@aarzlli I thought that is what @dlsniper you are correct. I added a runtime.Breakpoint() line to where I was trying to debug but that just caused the separate program to crash -- I assume because I was not fast enough to attach to it. I could put the code in an controlled loop near where I want to debug but that sounds like a hack. Also, wouldn't that mean that the plugin would have been compiled without the "delve" modifications? I have been able to solve my original bug ( using print statements :) ) , so there is no rush. However, what should be delve's best practices for applications that behave like terraform? |
@sodre I was trying to determine if the problem is the If you have a way to start the plugins separately and point the main program to them, then you can do that. Otherwise using delve will require either changing the main program or changing the plugins. Delve does not currently follow |
@aarzilli got it! I'll see how that can be done. |
On Linux where we use However, for OSX and Windows I am not so sure. Windows may have something for this in their debug APIs. For OSX, since we're dealing mostly with mach exceptions, and lower-level syscalls for process manipulation, we need a way to determine when the traced process has fork'ed so we can begin tracing the new child. After some quick research I couldn't find a way to get notifications upon a |
Derek, Thanks for looking into this, would dtrace be a better equivalent in the OS X world? https://community.oracle.com/thread/1921595?start=0&tstart=0 Patrick
|
The limitation of tracing programs using Turns out the https://github.com/mitchellh/panicwrap/blob/master/panicwrap.go#L143
btw, I was able to figure this out thanks to delve, except once the process executes the line above, delve can no longer follow... |
I just returned from Hashicon and got a tip from the core Terraform team (they use delve too!). This is how I got debugging to work with Terraform:
NOTE: this technique only works with Terraform core. Debugging the Terraform plug-ins is still an issue. The key is setting the above environment variable. I won't even try to pretend explaining why this works, but you can find where I got the mysterious values from here: https://github.com/mitchellh/panicwrap/search?utf8=%E2%9C%93&q=DEFAULT_COOKIE_KEY |
@sjwl hi, I saw your post, I am currently trying to work on terraform-core. Could you post the step, I don't know how to feed this json into my delve. |
@sjwl funny to see your post here! Thanks for leading me in the right direction! @huydinhle it should be noted that the JSON above is a https://github.com/microsoft/vscode I've been playing with this today on OS X and Linux, and my findings so far are:
Also, don't necessarily build the binary with |
This should be fixed on master for OSX. |
Are there any updates to this issue? SPecifically, how to debug custom plugin/providers? |
For @farvour and anyone else looking for an answer: This is quite a late reply, but I thought I'd drop in and say: providers are actually one of the easier things to debug in Terraform with Delve! The key to doing it is to debug it through Delve's Then, run:
The key to remember is that since you have to pass your test arguments over to the actual test binary directly instead of proxying them with In the debugger, set your breakpoints, In some of the providers I have worked on, you will see a
|
Going to close this out as it seems to be working now. Please reopen if that is not the case. |
This is quite an old thread and I'm probably screaming into the void, but I'm trying to debug a terraform provider acceptance test with vscode and delve. I'm trying to pass a The debugger config: {
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {
"TF_ACC": "1"
},
"args": [
"-test.v",
],
"buildFlags": "-v -tags=all",
"trace": "log",
"envFile": "${workspaceRoot}/.env",
"showLog": true
}
]
} Which results in the following error: API server listening at: 127.0.0.1:37336
--- FAIL: TestAccResourceAuthorization_CRUD (0.00s)
testing.go:555: Acceptance tests must be run with the -v flag on tests
FAIL
Process exiting with code: 0 Any help would be appreciated. |
@polinasok is this something you would know? |
Hmm, I don't see anything obviously wrong with the configuration. It would be more bulletproof if you specified "test" mode explicitly, but based on the log, it seems to be resolving things correctly automatically. Is it possible that the condition that prints the error, tests for more than just testing.Verbose() (example), so something else is not configured correctly? vscode should log the delve command that it creates based on the configuration - "Running: /my/bin/dlv test ..." And then delve should log what it is going to run: "info layer=debugger launching process with args: ...". Do those look right? |
Hey! Thanks for your replies @aarzilli @polinasok! I've managed to figure out a way to get it to work here: https://dev.to/eliises/debug-terraform-azuredevops-provider-with-vscode-c24 The only problem is that it doesn't work by clicking the |
|
dlv version
)?Delve Debugger
Version: 0.11.0-alpha
Build: 26ce16f
go version
)?go version go1.6 darwin/amd64
OS X
I tried to debug hashicorp/terraform application.
I expected to debugger to be able to find the other plugins that Terraform depends.
The text was updated successfully, but these errors were encountered: