Skip to content

Commit 54d85a3

Browse files
etiennejournetEtienne Journetmirii1994
authored
Added datasource and provider for grafana_dashboard (#109)
* Added datasource and provider for grafana_dashboard * Added the proper check to prevent terraform from failing if the dashboard doesn't exist during Read * updates resource * test * update dependencies * working * ds * add example * docs * update to client 1.16 * readme * import note * note --------- Co-authored-by: Etienne Journet <etienne.journet@non.se.com> Co-authored-by: mirii1994 <miri.ignatiev@logz.io>
1 parent 36ce9c6 commit 54d85a3

File tree

16 files changed

+723
-56
lines changed

16 files changed

+723
-56
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Grafana Dashboard Datasource
2+
3+
Use this data source to access information about existing Logz.io Grafana Dashboard.
4+
5+
## Argument Reference
6+
7+
* `dashboard_uid` - The unique identifier (uid) of the dashboard.
8+
9+
## Attribute Reference
10+
11+
* `url` - Dashboard url.
12+
* `folder_uid` - The unique identifier (uid) of a folder to store your dashboard.
13+
* `dashboard_json` - The complete dashboard model, to create a new dashboard, in a JSON format.

docs/resources/grafana_dashboard.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Grafana Dashboard Provider
2+
3+
Provides a Logz.io Grafana dashboard resource. This can be used to create and manage Grafana dashboards in Logz.io.
4+
5+
* Learn more about Logz.io's Grafana dashboard API in [Logz.io Docs](https://docs.logz.io/api/#tag/Grafana-dashboards).
6+
7+
## Example Usage
8+
9+
```hcl
10+
resource "logzio_grafana_dashboard" "my_dashboard" {
11+
dashboard_json = <<EOD
12+
{
13+
"title": "a title",
14+
"uid": "my_dashboard_uid",
15+
"panels": []
16+
}
17+
EOD
18+
folder_uid = "my_folder_uid"
19+
message = "my message"
20+
overwrite = true
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
### Required:
27+
28+
* `folder_uid` - (String) The unique identifier (uid) of a folder to store your dashboard. You cannot use `General` folder or the folder generated by logz.io - `Logz.io Dashboards` - to place your alerts.
29+
* `dashboard_json` - (String) The complete dashboard model, to create a new dashboard, in a JSON format. **Note** that your model should contain a `uid` field. Once created, you cannot change tha uid.
30+
31+
### Optional:
32+
33+
* `message` - (String) A commit message for the version history.
34+
* `overwrite` - (Boolean) Set to true if you want to overwrite existing dashboard with newer version.
35+
36+
## Attribute Reference
37+
38+
* `dashboard_id` - (Int) The identifier (id) of a dashboard.
39+
* `dashboard_uid` - (String) The unique identifier (uid) of a dashboard.
40+
* `url` - (String) Dashboard url.
41+
* `version` - (Int) Dashboard version.
42+
43+
### Import Logz.io Grafana Dashboard as Terraform resource
44+
45+
You can import existing dashboard as follows:
46+
47+
```
48+
terraform import logzio_grafana_dashboard.my_dashboard <FETCHER-ID>
49+
```

examples/grafana_dashoboard/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "api_token" {
2+
type = string
3+
description = "your logzio API token"
4+
}
5+
6+
provider "logzio" {
7+
api_token = var.api_token
8+
}
9+
10+
resource "logzio_grafana_dashboard" "my_dashboard" {
11+
dashboard_json = <<EOD
12+
{
13+
"title": "a title",
14+
"uid": "my_dashboard_uid",
15+
"panels": []
16+
}
17+
EOD
18+
folder_uid = "my_folder_uid"
19+
message = "my message"
20+
overwrite = true
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
export TF_LOG=DEBUG
3+
TF_VAR_api_token=${LOGZIO_API_TOKEN} terraform destroy
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
export TF_LOG=DEBUG
3+
terraform init
4+
TF_VAR_api_token=${LOGZIO_API_TOKEN} terraform plan -out terraform.plan
5+
terraform apply terraform.plan

go.mod

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ go 1.18
55
require (
66
github.com/avast/retry-go v3.0.0+incompatible
77
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
8-
github.com/hashicorp/terraform-plugin-log v0.7.0
9-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
10-
github.com/logzio/logzio_terraform_client v1.15.0
8+
github.com/hashicorp/terraform-plugin-log v0.8.0
9+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
10+
github.com/logzio/logzio_terraform_client v1.16.0
1111
github.com/stretchr/testify v1.7.2
1212
)
1313

@@ -21,18 +21,18 @@ require (
2121
github.com/hashicorp/errwrap v1.0.0 // indirect
2222
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
2323
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
24-
github.com/hashicorp/go-hclog v1.2.1 // indirect
24+
github.com/hashicorp/go-hclog v1.4.0 // indirect
2525
github.com/hashicorp/go-multierror v1.1.1 // indirect
26-
github.com/hashicorp/go-plugin v1.4.6 // indirect
26+
github.com/hashicorp/go-plugin v1.4.8 // indirect
2727
github.com/hashicorp/go-uuid v1.0.3 // indirect
2828
github.com/hashicorp/go-version v1.6.0 // indirect
29-
github.com/hashicorp/hc-install v0.4.0 // indirect
30-
github.com/hashicorp/hcl/v2 v2.15.0 // indirect
29+
github.com/hashicorp/hc-install v0.5.0 // indirect
30+
github.com/hashicorp/hcl/v2 v2.16.1 // indirect
3131
github.com/hashicorp/logutils v1.0.0 // indirect
3232
github.com/hashicorp/terraform-exec v0.17.3 // indirect
33-
github.com/hashicorp/terraform-json v0.14.0 // indirect
34-
github.com/hashicorp/terraform-plugin-go v0.14.1 // indirect
35-
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
33+
github.com/hashicorp/terraform-json v0.15.0 // indirect
34+
github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
35+
github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
3636
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
3737
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
3838
github.com/mattn/go-colorable v0.1.12 // indirect
@@ -48,13 +48,14 @@ require (
4848
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
4949
github.com/vmihailenco/tagparser v0.1.1 // indirect
5050
github.com/zclconf/go-cty v1.12.1 // indirect
51-
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
52-
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect
53-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
54-
golang.org/x/text v0.3.7 // indirect
51+
golang.org/x/crypto v0.6.0 // indirect
52+
golang.org/x/mod v0.7.0 // indirect
53+
golang.org/x/net v0.6.0 // indirect
54+
golang.org/x/sys v0.5.0 // indirect
55+
golang.org/x/text v0.7.0 // indirect
5556
google.golang.org/appengine v1.6.6 // indirect
5657
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
57-
google.golang.org/grpc v1.50.1 // indirect
58+
google.golang.org/grpc v1.51.0 // indirect
5859
google.golang.org/protobuf v1.28.1 // indirect
5960
gopkg.in/yaml.v3 v3.0.1 // indirect
6061
)

0 commit comments

Comments
 (0)