Run terraform from source

136 views
Skip to first unread message

Justin

unread,
May 30, 2017, 3:47:05 AM5/30/17
to Terraform
I've gotten a basic "make dev" terraform dev env setup however, being new to go, I've had problems invoking terraform using 'go run' or anything of the sort. I really need to step through the execution of a terraform plugin so I can see 'ResourceData' being passed in and out of the plugin and see the Provider() function executed. On top of not knowing how to do this, go lacks anything like 'pdb.set_trace()' which I would really like to be able to dig into this code. Does anyone have any helpful tips? Thanks in advance.

Sander van Harmelen

unread,
May 30, 2017, 4:51:09 AM5/30/17
to <terraform-tool@googlegroups.com>
Hi Justin,

If you put `TF_FORK=0` in your env, it should prevent Terraform from forking (re-exec) it’s core binary. So then you should be able to use a debugger like Delve (https://github.com/derekparker/delve) from the command line or use your favourite editor. Unless that is vim/neovim which I use, as those don’t have debugger integration. But Atom, VSCode and Gogland (JetBrains) and likely others I don’t know do have debugging capabilities for debugging Go built into their products.

One issue you will still have is that plugins are spawn in their own process. Even if they are builtin providers, they will be started in their own process by calling the `terraform` binary with a few specific parameters which will launch the plugin instead of the core binary itself. Maybe this sounds a bit fuzzy, but without going through all the nitty gritty details this is the easiest way to describe how things work.

So it should be fairly easy to debug Terraform core, but it will be harder to debug plugins by using a debugger. I myself got used to not use a debugger since I'm working almost exclusively in Go for a few years now. Just adding some `log.Printf` statements in the right places or `pretty.Print` (https://github.com/kr/pretty) more then often does the job just as well… 

Sander


On 30 May 2017, at 09:47: 05, Justin <justinp...@gmail.com> wrote:

I've gotten a basic "make dev" terraform dev env setup however, being new to go, I've had problems invoking terraform using 'go run' or anything of the sort. I really need to step through the execution of a terraform plugin so I can see 'ResourceData' being passed in and out of the plugin and see the Provider() function executed. On top of not knowing how to do this, go lacks anything like 'pdb.set_trace()' which I would really like to be able to dig into this code. Does anyone have any helpful tips? Thanks in advance.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/a20dd8db-73c7-4099-8065-cb3b4ba3281c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin

unread,
May 30, 2017, 1:35:01 PM5/30/17
to terrafo...@googlegroups.com
Thanks Sander, 

Thanks to you I can now step through terraform core with delve and I have also followed the advice of https://www.terraform.io/docs/internals/debugging.html However, I'm still curious how to actually step through the provider code with a debugger. I understand how the providers are called but does anyone here actually have a working setup of tracing (with a debugger) through their provider code? My worry with delve is that in order to prevent trashing it locks you into one goroutine and that it may be quite difficult to step into the provider execution path. 


Sander


To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/QGgzDO4jzNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/0F3DEF00-E5B0-4E0C-B283-8645AE52D4DF%40xanzy.io.

Sander van Harmelen

unread,
May 31, 2017, 11:37:51 AM5/31/17
to terrafo...@googlegroups.com
Not sure if this will work, but I think it’s the only way to achieve your goal… If you set a breakpoint in the core binary right after the call to initialise a new provider, that would cause the execution to be paused and gives you some time to connect Delve to the newly spawn process (dlv attach pid). You would then have 2 delve sessions to both the core binary and the spawned provider…

Cheers,

Sander


To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CALQ-eLSg2ncVVE93y-fProeEd3zrF5KQzT9m7-Ag9QAxm_sZtg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages