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) }