[Plugin Development] How can i debug my step functions

I am writing a new Packer Builder and I need to debug my step functions during runtime. The acceptance test apparatus seems to execute the Packer CLI using a compiled binary (see code below)… Is it possible to run tests against the Packer Steps with a in-memory compilation so I can set break points, etc?

What I am imagining is something like Terraform Providers acceptance tests which doesnt test a pre-compiled binary but instead tests the source in the development env.

Hi @dmullen,

Compiling + loading plugins from source are not something Packer supports, but might be an idea down the road.
In the meantime the best way to debug using something like delve would probably be to have your process wait on an action at the beginning of execution, and using dlv attach you should be able to attach to the process and start placing breakpoints and step-by-step debugging it.

After that once delve is spawned I believe you may be able to instrument it through an IDE like VSCode, but I’ve never tried this so I’d be happy to hear if you can make this happen.

Acceptance tests on Packer and plugins generally imply Packer and/or the plugin being debugged are up-to-date and running the version(s) you want to test, and essentially automatically run the command as if you were in a shell, so in that case you won’t be able to do much more than what I suggested earlier.

This might be a good opportunity for writing documentation on that front, AFAIK we don’t have anything regarding debugging plugins with Packer.

Hope that helps!

Thank you for the response. I spent a while trying to get delve to attach but it was difficult since there are several subprocesses. In the end I wound up figuring out my immediate issue using print statements.

That being said, I have opened a feature request for yall to hopefully help the community with an integration test apparatus.

Acceptance tests on Packer and plugins generally imply Packer and/or the plugin being debugged are up-to-date and running the version(s) you want to test

I believe this is a better use of the term “acceptance” test over what Terraform team uses. For that reason i’m calling them “integration tests”.

This might be a good opportunity for writing documentation on that front, AFAIK we don’t have anything regarding debugging plugins with Packer.

Yes this would be helpful! I looked all over and couldnt even find the word “test” in the customer builder docs LOL