From b8c94f1424c4103fb050146550564a7ebfbbb7c6 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 13 Feb 2024 12:14:22 +0200 Subject: [PATCH] Add debug capabilities to main.go Add some necessary code for execution of the provider with a debugger, e.g delve. Signed-off-by: Kobi Samoray --- main.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 71421cab2..ba7551bf0 100644 --- a/main.go +++ b/main.go @@ -4,15 +4,33 @@ package main import ( + "context" + "flag" + "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" "github.com/vmware/terraform-provider-nsxt/nsxt" ) func main() { - plugin.Serve(&plugin.ServeOpts{ + var debugMode bool + flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := &plugin.ServeOpts{ ProviderFunc: func() *schema.Provider { return nsxt.Provider() }, - }) + } + + if debugMode { + err := plugin.Debug(context.Background(), "registry.terraform.io/vmware/nsxt", opts) + if err != nil { + log.Fatal(err.Error()) + } + return + } + + plugin.Serve(opts) }