Skip to content

Instantly share code, notes, and snippets.

@pancudaniel7
Last active January 10, 2024 23:51
Show Gist options
  • Save pancudaniel7/6fd45122a6c2b6fc58f7e3ab186fa2f5 to your computer and use it in GitHub Desktop.
Save pancudaniel7/6fd45122a6c2b6fc58f7e3ab186fa2f5 to your computer and use it in GitHub Desktop.

Pulumi Go remote debugging

In this guide, we will walk through the setup and steps needed to start a remote debugging session for a Pulumi Go application.

Pre-installation Requirements

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 Debugger

Delve is a debugger for the Go programming language, designed to provide a more powerful and user-friendly experience than GDB.

Installing Delve

Open a terminal and run the following command:

go install github.com/go-delve/delve/cmd/dlv@latest

Remote debug script

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

Pulumi.yaml update

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

GoLand Remote Debug configuration

Now we can create a Goland remote debugging configuration as so:

Screenshot 2024-01-11 at 01 14 07

Run Pulumi Up

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

Start Goland debugger

Finally, set a breakpoint in your code and click the debug button for GoLand remote debugger configuration

Screenshot 2024-01-11 at 01 18 36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment