diff --git a/nsxt/provider.go b/nsxt/provider.go index c3c3ac65e..0655c1960 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -12,6 +12,8 @@ import ( "log" "math/rand" "net/http" + "net/http/httputil" + "os" "regexp" "strings" "time" @@ -763,6 +765,22 @@ func (processor remoteAuthHeaderProcessor) Process(req *http.Request) error { return nil } +type logRequestProcessor struct { +} + +func newLogRequestProcessor() *logRequestProcessor { + return &logRequestProcessor{} +} + +func (processor logRequestProcessor) Process(req *http.Request) error { + reqDump, err := httputil.DumpRequestOut(req, true) + if err != nil { + log.Fatal(err) + } + log.Printf("Issuing request towards NSX:\n%s", reqDump) + return nil +} + type bearerAuthHeaderProcessor struct { Token string } @@ -979,6 +997,10 @@ func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[strin log.Printf("[INFO]: Session headers configured for policy objects") } + if os.Getenv("TF_LOG_PROVIDER") != "" { + requestProcessors = append(requestProcessors, newLogRequestProcessor().Process) + } + if len(requestProcessors) > 0 { connectorOptions = append(connectorOptions, client.WithRequestProcessors(requestProcessors...)) }