Skip to content

Commit

Permalink
Add debug capabilities to main.go
Browse files Browse the repository at this point in the history
Add some necessary code for execution of the provider with a debugger,
e.g delve.

Signed-off-by: Kobi Samoray <[email protected]>
  • Loading branch information
ksamoray committed Feb 13, 2024
1 parent c124a25 commit b8c94f1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b8c94f1

Please sign in to comment.