Skip to content

Commit fbd7a2d

Browse files
committed
wip
1 parent 42597b2 commit fbd7a2d

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Run [acceptance tests](https://www.terraform.io/docs/extend/testing/acceptance-t
3333
# In one terminal, run a Grafana container.
3434
# You may optionally override the image tag...
3535
# GRAFANA_VERSION=7.1.1 \
36-
make test-serve
36+
make test-serv
3737

3838
# In another...
3939
GRAFANA_URL=http://localhost:3000 \

grafana/provider.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package grafana
22

33
import (
4+
"crypto/tls"
5+
"crypto/x509"
6+
"io/ioutil"
47
"net/url"
58
"strings"
69

@@ -28,6 +31,30 @@ func Provider() terraform.ResourceProvider {
2831
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_AUTH", nil),
2932
Description: "Credentials for accessing the Grafana API.",
3033
},
34+
"tls_key": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_TLS_KEY", nil),
38+
Description: "Client TLS key for accessing the Grafana API.",
39+
},
40+
"tls_cert": {
41+
Type: schema.TypeString,
42+
Optional: true,
43+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_TLS_CERT", nil),
44+
Description: "Client TLS cert for accessing the Grafana API.",
45+
},
46+
"ca_cert": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_CA_CERT", nil),
50+
Description: "CA cert bundle for validating the Grafana API's certificate.",
51+
},
52+
"insecure_skip_verify": {
53+
Type: schema.TypeBool,
54+
Optional: true,
55+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_INSECURE_SKIP_VERIFY", nil),
56+
Description: "Skip TLS certificate verification",
57+
},
3158
},
3259

3360
ResourcesMap: map[string]*schema.Resource{
@@ -49,7 +76,34 @@ func Provider() terraform.ResourceProvider {
4976
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
5077
auth := strings.SplitN(d.Get("auth").(string), ":", 2)
5178
cli := cleanhttp.DefaultClient()
52-
cli.Transport = logging.NewTransport("Grafana", cli.Transport)
79+
transport := cleanhttp.DefaultTransport()
80+
81+
// TLS Config
82+
tlsKey := d.Get("tls_key").(string)
83+
tlsCert := d.Get("tls_cert").(string)
84+
caCert := d.Get("ca_cert").(string)
85+
insecure := d.Get("insecure_skip_verify").(bool)
86+
if caCert != "" {
87+
ca, err := ioutil.ReadFile(caCert)
88+
if err != nil {
89+
return nil, err
90+
}
91+
pool := x509.NewCertPool()
92+
pool.AppendCertsFromPEM(ca)
93+
transport.TLSClientConfig.RootCAs = pool
94+
}
95+
if tlsKey != "" && tlsCert != "" {
96+
cert, err := tls.LoadX509KeyPair(tlsCert, tlsKey)
97+
if err != nil {
98+
return nil, err
99+
}
100+
transport.TLSClientConfig.Certificates = []tls.Certificate{cert}
101+
}
102+
if insecure {
103+
transport.TLSClientConfig.InsecureSkipVerify = true
104+
}
105+
106+
cli.Transport = logging.NewTransport("Grafana", transport)
53107
cfg := gapi.Config{
54108
Client: cli,
55109
}

website/docs/index.html.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ The provider configuration block accepts the following arguments:
2222
are provided in a single string and separated by a colon. May alternatively
2323
be set via the ``GRAFANA_AUTH`` environment variable.
2424

25+
* ``tls_key`` - (Optional) Client TLS key file to use to authenticate to the
26+
Grafana server. May alternatively be set via the ``GRAFANA_TLS_KEY``
27+
environment variable.
28+
29+
* ``tls_cert`` - (Optional) Client TLS certificate file to use to authenticate
30+
to the Grafana server. May alternatively be set via the ``GRAFANA_TLS_CERT``
31+
environment variable.
32+
33+
* ``ca_cert`` - (Optional) Certificate CA bundle to use to verify the
34+
Grafana server's certifiate.. May alternatively be set via the
35+
``GRAFANA_CA_CERT`` environment variable.
36+
37+
* ``insecure_skip_verify`` - (Optional) Bool. Disable verification of the
38+
Grafana Server's certificate. May alternatively be set via the
39+
``GRAFANA_INSECURE_SKIP_VERIFY`` environment variable.
40+
2541
Use the navigation to the left to read about the available resources.
2642

2743
## Example Usage

0 commit comments

Comments
 (0)