-
Notifications
You must be signed in to change notification settings - Fork 12
/
grafana.tf
227 lines (214 loc) · 5.46 KB
/
grafana.tf
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
# Grafana variables
variable "grafana_enabled" {
default = true
description = "Enable Grafana Dashboards. Includes example dashboards and Prometheus, OCI Logging and OCI Metrics datasources"
}
# Grafana Helm chart
## https://github.com/grafana/helm-charts/blob/main/charts/grafana/README.md
## https://artifacthub.io/packages/helm/grafana/grafana
resource "helm_release" "grafana" {
name = "grafana"
repository = local.helm_repository.grafana
chart = "grafana"
version = local.helm_repository.grafana_version
namespace = kubernetes_namespace.cluster_tools.0.id
wait = false
set {
name = "grafana\\.ini.server.root_url"
value = "%(protocol)s://%(domain)s:%(http_port)s/grafana"
type = "string"
}
# set {
# name = "grafana\\.ini.server.serve_from_sub_path"
# value = "true"
# }
values = [
<<EOF
dashboards:
default:
k8s-cluster:
gnetId: 7249
revision: 1
datasource: Prometheus
k8s-cluster-metrics:
gnetId: 11663
revision: 1
datasource: Prometheus
k8s-cluster-metrics-simple:
gnetId: 6417
revision: 1
datasource: Prometheus
k8s-pods-monitoring:
gnetId: 13498
revision: 1
datasource: Prometheus
k8s-memory:
gnetId: 13421
revision: 1
datasource: Prometheus
k8s-networking:
gnetId: 12658
revision: 1
datasource: Prometheus
k8s-cluster-autoscaler:
gnetId: 3831
revision: 1
datasource: Prometheus
k8s-hpa:
gnetId: 10257
revision: 1
datasource: Prometheus
k8s-pods:
gnetId: 6336
revision: 1
datasource: Prometheus
spring-boot:
gnetId: 12464
revision: 2
datasource: Prometheus
nginx-ingress-controller:
gnetId: 9614
revision: 1
datasource: Prometheus
oci-compute:
gnetId: 13596
revision: 1
datasource: Oracle Cloud Infrastructure Metrics
oci-oke:
gnetId: 13594
revision: 1
datasource: Oracle Cloud Infrastructure Metrics
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: true
editable: true
options:
path: /var/lib/grafana/dashboards/default
sidecar:
datasources:
enabled: true
label: grafana_datasource
dashboards:
enabled: true
label: grafana_dashboard
persistence:
enabled: true
plugins:
- oci-logs-datasource
- oci-metrics-datasource
- grafana-kubernetes-app
- grafana-worldmap-panel
- grafana-piechart-panel
- btplc-status-dot-panel
datasources:
datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://prometheus-server.${kubernetes_namespace.cluster_tools.0.id}.svc.cluster.local
access: proxy
isDefault: true
disableDeletion: true
editable: false
- name: Oracle Cloud Infrastructure Metrics
type: oci-metrics-datasource
access: proxy
disableDeletion: true
editable: true
jsonData:
tenancyOCID: ${var.tenancy_ocid}
defaultRegion: ${var.region}
environment: "OCI Instance"
- name: Oracle Cloud Infrastructure Logs
type: oci-logs-datasource
access: proxy
disableDeletion: true
editable: true
jsonData:
tenancyOCID: ${var.tenancy_ocid}
defaultRegion: ${var.region}
environment: "OCI Instance"
EOF
]
count = var.grafana_enabled ? 1 : 0
}
## Grafana Ingress
resource "kubernetes_ingress_v1" "grafana" {
wait_for_load_balancer = true
metadata {
name = "grafana"
namespace = kubernetes_namespace.cluster_tools.0.id
annotations = local.ingress_nginx_annotations
}
spec {
ingress_class_name = "nginx"
rule {
http {
path {
path = "/grafana(/|$)(.*)"
path_type = "Prefix"
backend {
service {
name = "grafana"
port {
number = 80
}
}
}
}
}
}
dynamic "rule" {
for_each = local.ingress_hosts
content {
host = rule.value
http {
path {
path = "/grafana(/|$)(.*)"
path_type = "Prefix"
backend {
service {
name = "grafana"
port {
number = 80
}
}
}
}
}
}
}
tls {
secret_name = "grafana-${var.ingress_cluster_issuer}-tls"
hosts = local.ingress_hosts
}
}
depends_on = [helm_release.ingress_nginx, helm_release.grafana]
count = (var.grafana_enabled && var.ingress_nginx_enabled) ? 1 : 0
}
## Kubernetes Secret: Grafana Admin Password
data "kubernetes_secret" "grafana" {
metadata {
name = "grafana"
namespace = kubernetes_namespace.cluster_tools.0.id
}
depends_on = [helm_release.grafana]
count = var.grafana_enabled ? 1 : 0
}
locals {
grafana_admin_password = var.grafana_enabled ? data.kubernetes_secret.grafana.0.data.admin-password : "Grafana_Not_Deployed"
}
output "grafana_admin_password" {
value = var.grafana_enabled ? local.grafana_admin_password : null
sensitive = true
}