Skip to content

Commit de7a0b7

Browse files
Merge pull request grafana#122 from grafana/grafana-fork
Update From Grafana Fork
2 parents c9213b9 + fc2f2c2 commit de7a0b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1519
-910
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ install:
1919
script:
2020
- make test
2121
- make vet
22-
- make website-test
2322

2423
branches:
2524
only:

GNUmakefile

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ build: fmtcheck
1010
go install
1111

1212
test: fmtcheck
13-
go test -i $(TEST) || exit 1
14-
echo $(TEST) | \
15-
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
13+
go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4
1614

1715
testacc: fmtcheck
1816
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
@@ -39,28 +37,10 @@ fmtcheck:
3937
errcheck:
4038
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
4139

42-
4340
test-compile:
4441
@if [ "$(TEST)" = "./..." ]; then \
4542
echo "ERROR: Set TEST to a specific package. For example,"; \
4643
echo " make test-compile TEST=./$(PKG_NAME)"; \
4744
exit 1; \
4845
fi
4946
go test -c $(TEST) $(TESTARGS)
50-
51-
website:
52-
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
53-
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
54-
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
55-
endif
56-
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
57-
58-
website-test:
59-
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
60-
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
61-
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
62-
endif
63-
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
64-
65-
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website website-test
66-

README.md

Lines changed: 32 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,46 @@
1-
Terraform Provider
2-
==================
1+
<a href="https://terraform.io">
2+
<img src="https://cdn.rawgit.com/hashicorp/terraform-website/master/content/source/assets/images/logo-hashicorp.svg" title="Terraform" align="right" height="50" />
3+
</a>
34

4-
- Website: https://www.terraform.io
5-
- [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
6-
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)
5+
# Terraform Provider for Grafana
76

8-
<img src="https://cdn.rawgit.com/hashicorp/terraform-website/master/content/source/assets/images/logo-hashicorp.svg" width="600px">
7+
- Terraform website: https://terraform.io
8+
- Grafana website: https://grafana.com
9+
- Provider Documentation: https://registry.terraform.io/providers/grafana/grafana/latest/docs
10+
- Terraform Chat: [Terraform Gitter](https://gitter.im/hashicorp-terraform/Lobby)
11+
- Grafana Chat: [Grafana #terraform Slack channel](https://grafana.slack.com/archives/C017MUCFJUT)
12+
- Terraform Mailing List: [Google Groups](http://groups.google.com/group/terraform-tool)
913

10-
Requirements
11-
------------
14+
## Development
1215

13-
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
14-
- [Go](https://golang.org/doc/install) 1.11 (to build the provider plugin)
16+
If you're new to provider development, a good place to start is the [Extending
17+
Terraform](https://www.terraform.io/docs/extend/index.html) docs.
1518

16-
Building The Provider
17-
---------------------
19+
Set up your local environment by installing [Go](http://www.golang.org). Also
20+
recommended is [Docker](https://docs.docker.com/install/). Docker is not
21+
required, but it makes running a local Grafana instance for acceptance tests
22+
very easy.
1823

19-
Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provider-grafana`
24+
Run [unit tests](https://www.terraform.io/docs/extend/testing/unit-testing.html):
2025

2126
```sh
22-
$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers
23-
$ git clone [email protected]:terraform-providers/terraform-provider-grafana
27+
make test
2428
```
2529

26-
Enter the provider directory and build the provider
30+
Run [acceptance tests](https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html):
2731

2832
```sh
29-
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-grafana
30-
$ make build
33+
# In one terminal, run a Grafana container.
34+
# You may optionally override the image tag...
35+
# GRAFANA_VERSION=7.1.1 \
36+
make test-serve
37+
38+
# In another...
39+
GRAFANA_URL=http://localhost:3000 \
40+
GRAFANA_AUTH=admin:admin \
41+
make testacc
3142
```
3243

33-
Developing the Provider
34-
---------------------------
35-
36-
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
37-
38-
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
39-
40-
```sh
41-
$ make bin
42-
...
43-
$ $GOPATH/bin/terraform-provider-grafana
44-
...
45-
```
46-
47-
In order to test the provider, you can simply run `make test`.
48-
49-
```sh
50-
$ make test
51-
```
52-
53-
In order to run the full suite of Acceptance tests, run `make testacc`. This should be
54-
performed before merging or opening pull requests.
55-
56-
```sh
57-
$ GRAFANA_URL=http://localhost:3000 GRAFANA_AUTH=admin:admin make testacc
58-
```
59-
60-
This requires a running Grafana server locally. This provider targets
61-
the latest version of Grafana, but older versions should be compatible where
62-
possible. In some cases, older versions of this provider will work with
63-
older versions of Grafana.
64-
65-
If you have [Docker](https://docs.docker.com/install/) installed, you can
66-
run Grafana with the following command:
67-
68-
```sh
69-
$ make test-serv
70-
```
71-
72-
By default, this will use the latest version of Grafana based on their
73-
Docker repository. You can specify the version with the following:
74-
75-
```sh
76-
$ GRAFANA_VERSION=3.1.1 make test-serv
77-
```
78-
79-
This command will run attached and will stop the Grafana server when
80-
interrupted. Images will be cached locally by Docker so it is quicky to
81-
restart the server as necessary. The server will use the default port and
82-
credentials for the `GRAFANA_AUTH` and `GRAFANA_URL` environment variables.
83-
84-
Nightly acceptance tests are run against the `latest` tag of the Grafana
85-
maintained Docker image.
44+
This codebase leverages
45+
[grafana/grafana-api-golang-client](https://github.com/grafana/grafana-api-golang-client) as its Grafana API
46+
client. All resources and data sources should leverage this.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-grafana
33
go 1.14
44

55
require (
6+
github.com/grafana/grafana-api-golang-client v0.0.0-20200812141400-4d890c757d56
67
github.com/hashicorp/hcl v1.0.0 // indirect
78
github.com/hashicorp/terraform v0.12.2
8-
github.com/nytm/go-grafana-api v0.5.0
99
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01 h1:OgCNGSnEalfkR
139139
github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01/go.mod h1:wjDF8z83zTeg5eMLml5EBSlAhbF7G8DobyI1YsMuyzw=
140140
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
141141
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
142+
github.com/grafana/grafana-api-golang-client v0.0.0-20200812141400-4d890c757d56 h1:+XIU6AjxfFIu3yOHC+M1Hwz7dUAs5zc/ugJ9cCfvUNA=
143+
github.com/grafana/grafana-api-golang-client v0.0.0-20200812141400-4d890c757d56/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw=
142144
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
143145
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
144146
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=

grafana/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/hashicorp/terraform/helper/schema"
66
"github.com/hashicorp/terraform/terraform"
77

8-
gapi "github.com/nytm/go-grafana-api"
8+
gapi "github.com/grafana/grafana-api-golang-client"
99
)
1010

1111
func Provider() terraform.ResourceProvider {
@@ -32,6 +32,7 @@ func Provider() terraform.ResourceProvider {
3232
"grafana_data_source": ResourceDataSource(),
3333
"grafana_folder": ResourceFolder(),
3434
"grafana_organization": ResourceOrganization(),
35+
"grafana_user": ResourceUser(),
3536
},
3637

3738
ConfigureFunc: providerConfigure,

grafana/resource_alert_notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strconv"
88
"time"
99

10+
gapi "github.com/grafana/grafana-api-golang-client"
1011
"github.com/hashicorp/terraform/helper/schema"
11-
gapi "github.com/nytm/go-grafana-api"
1212
)
1313

1414
var (

grafana/resource_alert_notification_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strconv"
77
"testing"
88

9-
gapi "github.com/nytm/go-grafana-api"
9+
gapi "github.com/grafana/grafana-api-golang-client"
1010

1111
"github.com/hashicorp/terraform/helper/resource"
1212
"github.com/hashicorp/terraform/terraform"

grafana/resource_dashboard.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"strings"
78

89
"github.com/hashicorp/terraform/helper/schema"
910

10-
gapi "github.com/nytm/go-grafana-api"
11+
gapi "github.com/grafana/grafana-api-golang-client"
1112
)
1213

1314
func ResourceDashboard() *schema.Resource {
@@ -68,7 +69,7 @@ func ReadDashboard(d *schema.ResourceData, meta interface{}) error {
6869

6970
dashboard, err := client.Dashboard(slug)
7071
if err != nil {
71-
if err.Error() == "404 Not Found" {
72+
if strings.HasPrefix(err.Error(), "status: 404") {
7273
log.Printf("[WARN] removing dashboard %s from state because it no longer exists in grafana", slug)
7374
d.SetId("")
7475
return nil

grafana/resource_dashboard_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"regexp"
66
"testing"
77

8-
gapi "github.com/nytm/go-grafana-api"
8+
gapi "github.com/grafana/grafana-api-golang-client"
99

1010
"github.com/hashicorp/terraform/helper/resource"
1111
"github.com/hashicorp/terraform/terraform"

0 commit comments

Comments
 (0)