Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

chore: add information on how to debug tfgen #4067

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,64 @@ Once Pulumi runs or tests are initiated with the `PULUMI_DEBUG_PROVIDERS` enviro
{{< notes type="warning" >}}
**Terminating the Provider Process**: Be cautious when terminating the provider process as the Pulumi state can get out of sync with the actual cloud resources. When in doubt, `pulumi refresh` will address this.
{{< /notes >}}

## Debugging Bridged Providers

### Debugging tfgen

If you need to debug tfgen in one of the providers, you first have to start
tfgen using [dlv](https://github.com/go-delve/delve) exec.

#### Install dlv

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

#### Run tfgen with dlv exec

```shell
make debug_tfgen
```

#### Using local pulumi-terraform-bridge

If you want to use a local `pulumi-terraform-bridge` you can use [go
workspaces](https://go.dev/doc/tutorial/workspaces) to build the local provider
along with the local `pulumi-terraform-bridge`.

For example, if you had the following directory structure:

```shell
$ ls
pulumi-my-provider # YOUR provider
pulumi-terraform-bridge # github.com/pulumi/pulumi-terraform-bridge

$ cd pulumi-my-provider
```

Then you can run the following commands:

```shell
$ go work init
$ go work use -r ./provider
$ go work use -r ../pulumi-terraform-bridge
```

Then you can re-build tfgen to use the local bridge.

```shell
make tfgen_build_only
```

#### Attaching to the debugger in VS Code

For VS Code you can follow these steps to connect to the debugger.

1. Navigate to **Run -> Add Configuration** and add the **Go: Connect to server** configuration
![Screenshot of VS Code configuration for debugging providers](/docs/using-pulumi/pulumi-packages/img/vscode-launch-config-connect-to-server.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing; can you add a space above and below the screenshot. thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@interurban when I do that I get the below lint error. It looks like I can add a line either above or below but not both.

themes/default/content/docs/using-pulumi/pulumi-packages/debugging-provider-packages.md:
Line 114: Ordered list item prefix [Expected: 1; Actual: 2; Style: 1/2/3].
Line 115: Ordered list item prefix [Expected: 2; Actual: 3; Style: 1/2/3].


2. Edit "name": `"Connect to server"` to give it a descriptive name
3. Connect to server

![Screenshot of VS Code configuration for debugging tfgen](/docs/using-pulumi/pulumi-packages/img/vscode-debug-config-connect-to-server.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading