66// VARIABLES
77
88variable "dc" {
9- description = " Data centers that the job is eligible to run in"
9+ description = " data centers that the job is eligible to run in"
1010 type = list (string )
1111}
1212
1313variable "namespace" {
14- description = " Namespace that the job runs in"
14+ description = " namespace that the job runs in"
1515 type = string
1616 default = " default"
1717}
1818
1919variable "hosts" {
20- description = " Host constraint for the job, if empty exactly one allocation will be created "
20+ description = " host constraint for the job, defaults to one host "
2121 type = list (string )
2222 default = []
2323}
@@ -28,6 +28,24 @@ variable "service_provider" {
2828 default = " nomad"
2929}
3030
31+ variable "service_name" {
32+ description = " Service name"
33+ type = string
34+ default = " grafana-http"
35+ }
36+
37+ variable "service_dns" {
38+ description = " Service discovery DNS"
39+ type = list (string )
40+ default = []
41+ }
42+
43+ variable "service_type" {
44+ description = " Run as a service or system"
45+ type = string
46+ default = " service"
47+ }
48+
3149variable "docker_image" {
3250 description = " Docker image"
3351 type = string
@@ -39,6 +57,8 @@ variable "docker_always_pull" {
3957 default = false
4058}
4159
60+ // /////////////////////////////////////////////////////////////////////////////
61+
4262variable "port" {
4363 description = " Port for plaintext connections"
4464 type = number
@@ -84,17 +104,17 @@ variable "anonymous_role" {
84104// LOCALS
85105
86106locals {
87- logs_path = " ${ NOMAD_ALLOC_DIR } /logs"
88- db_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/db" : " /var/lib/grafana/data"
89- plugins_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/plugins" : " /var/lib/grafana/plugins"
107+ logs_path = " ${ NOMAD_ALLOC_DIR } /logs"
108+ db_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/db" : " /var/lib/grafana/data"
109+ plugins_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/plugins" : " /var/lib/grafana/plugins"
90110 provisioning_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/provisioning" : " /var/lib/grafana/provisioning"
91111}
92112
93113// /////////////////////////////////////////////////////////////////////////////
94114// JOB
95115
96116job "grafana" {
97- type = " service "
117+ type = var . service_type
98118 datacenters = var. dc
99119 namespace = var. namespace
100120
@@ -107,10 +127,10 @@ job "grafana" {
107127 // ///////////////////////////////////////////////////////////////////////////////
108128
109129 group "grafana" {
110- count = length (var. hosts ) == 0 ? 1 : length (var. hosts )
130+ count = ( length (var. hosts ) == 0 || var . service_type == " system " ) ? 1 : length (var. hosts )
111131
112132 dynamic "constraint" {
113- for_each = length (var. hosts ) == 0 ? [] : [ join (" ," , var. hosts ) ]
133+ for_each = length (var. hosts ) == 0 ? [] : [join (" ," , var. hosts )]
114134 content {
115135 attribute = node. unique . name
116136 operator = " set_contains_any"
@@ -154,16 +174,15 @@ job "grafana" {
154174 }
155175
156176 config {
157- image = var. docker_image
158- force_pull = var. docker_always_pull
159- ports = [" http" ]
177+ image = var. docker_image
178+ force_pull = var. docker_always_pull
179+ ports = [" http" ]
180+ dns_servers = var. service_dns
160181 volumes = compact ([
161182 var . data == " " ? " " : format (" %s:/var/lib/grafana" , var. data )
162183 ])
163184 }
164185
165186 } // task "daemon"
166-
167187 } // group "grafana"
168-
169188} // job "grafana"
0 commit comments