Skip to content

Commit

Permalink
chore: added debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
ricleal-fugue committed Jan 13, 2023
1 parent 9db46dc commit ecbab2b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/debug/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/hashicorp/terraform-provider-azurerm/internal/provider"
)

func main() {
// remove date and time stamp from log output as the plugin SDK already adds its own
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))

opts := &plugin.ServeOpts{
Debug: true,
ProviderFunc: provider.AzureProvider,
ProviderAddr: "snyk/azurerm",
}
plugin.Serve(opts)
}
57 changes: 57 additions & 0 deletions cmd/debug/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Debug

To debug the provider
## VSCODE

create debug config:


```json
{
"name": "Remote",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 8888,
"host": "127.0.0.1"
}
```

## Terminal 1

Compile the provider in debug mode

```sh
go build -gcflags="all=-N -l" ./cmd/debug
```

Launch `dlv` as:

```sh
dlv exec --listen=:8888 --headless --api-version=2 ./debug -- -debug
```

# VSCODE

Attach vs code to the debug session.

# Terminal 2

export the CLI config with:

```
provider_installation {
dev_overrides {
"snyk/azurerm" = "/Users/ricardol/git/terraform-provider-azurerm/debug"
}
}
```

TODO: this is not still working!!!!


```sh
export TF_CLI_CONFIG_FILE=/Users/ricardol/git/terraform-provider-azurerm/tmp/ex1/terraformrc
export TF_REATTACH_PROVIDERS=....
```

0 comments on commit ecbab2b

Please sign in to comment.