diff --git a/cmd/debug/main.go b/cmd/debug/main.go new file mode 100644 index 0000000000000..3784ffc074611 --- /dev/null +++ b/cmd/debug/main.go @@ -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) +} diff --git a/cmd/debug/readme.md b/cmd/debug/readme.md new file mode 100644 index 0000000000000..2e268296cb296 --- /dev/null +++ b/cmd/debug/readme.md @@ -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=.... +``` \ No newline at end of file