This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
forked from newrelic/terraform-provider-newrelic
/
config.go
65 lines (49 loc) · 1.47 KB
/
config.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
62
63
64
65
package newrelic
import (
"log"
synthetics "github.com/dollarshaveclub/new-relic-synthetics-go"
"github.com/hashicorp/terraform/helper/logging"
newrelic "github.com/paultyng/go-newrelic/api"
)
// Config contains New Relic provider settings
type Config struct {
APIKey string
APIURL string
}
// Client returns a new client for accessing New Relic
func (c *Config) Client() (*newrelic.Client, error) {
nrConfig := newrelic.Config{
APIKey: c.APIKey,
Debug: logging.IsDebugOrHigher(),
BaseURL: c.APIURL,
}
client := newrelic.New(nrConfig)
log.Printf("[INFO] New Relic client configured")
return &client, nil
}
// ClientInfra returns a new client for accessing New Relic
func (c *Config) ClientInfra() (*newrelic.InfraClient, error) {
nrConfig := newrelic.Config{
APIKey: c.APIKey,
Debug: logging.IsDebugOrHigher(),
BaseURL: c.APIURL,
}
client := newrelic.NewInfraClient(nrConfig)
log.Printf("[INFO] New Relic Infra client configured")
return &client, nil
}
// ClientSynthetics returns a new client for accessing New Relic Synthetics
func (c *Config) ClientSynthetics() (*synthetics.Client, error) {
conf := func(s *synthetics.Client) {
s.APIKey = c.APIKey
}
client, _ := synthetics.NewClient(conf)
log.Printf("[INFO] New Relic Synthetics client configured")
return client, nil
}
// ProviderConfig for the custom provider
type ProviderConfig struct {
Client *newrelic.Client
InfraClient *newrelic.InfraClient
Synthetics *synthetics.Client
}