-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
61 lines (48 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"flag"
"log"
"os"
"net/http"
"net/http/pprof"
_ "net/http/pprof"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/incident-io/terraform-provider-incident/internal/provider"
)
// Format terraform and generate docs:
//go:generate terraform fmt -recursive ./examples/
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
var (
version string = "dev" // set by goreleaser
)
func main() {
// If having performance issues, enable this envar and connect using:
// go tool pprof localhost:3333
if os.Getenv("INCIDENT_PROVIDER_PROFILE") == "1" {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
srv := &http.Server{Addr: "127.0.0.1:3333"}
srv.Handler = mux
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Println(err.Error())
}
}()
}
var debug bool
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
flag.Parse()
opts := providerserver.ServeOpts{
Address: "registry.terraform.io/incident-io/incident",
Debug: debug,
}
err := providerserver.Serve(context.Background(), provider.New(version), opts)
if err != nil {
log.Fatal(err.Error())
}
}