In this guide, we will walk through the setup and steps needed to start a remote debugging session for a Pulumi Go application.
Before you begin, ensure you have the necessary tools installed on your system. The following are required to successfully run and debug the application:
Delve is a debugger for the Go programming language, designed to provide a more powerful and user-friendly experience than GDB.
Open a terminal and run the following command:
go install github.com/go-delve/delve/cmd/dlv@latest
Copy the contents of the following script bash script and ensure you save it as debug.sh in the root directory of your Pulumi project to prepare for remote debugging.
#!/bin/bash
# This will build a binary of the app and start a remote debug process using dlv
# ! Don't forget to add this script in the pulumi root project dir
go build -o $HOME/pulumi_go_app -gcflags "all=-N -l" . && \
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec $HOME/pulumi_go_app
In order for our debug.sh script to be executed we will need to update Pulumi.yaml with the path to the script.
name: my-pulumi-project
description: Pulumi program
runtime:
name: go
options:
binary: /Home/[user]/workspace/pulumi-project/debug.sh
Now we can create a Goland remote debugging configuration as so:
Next we can run pulumi up command:
pulumi up
The process will listen until you start the remote debugger:
Type Name Plan Info
pulumi:pulumi:Stack xxxxx-dev API server listening at: [::]:2345
Finally, set a breakpoint in your code and click the debug button for GoLand remote debugger configuration