6
6
// VARIABLES
7
7
8
8
variable "dc" {
9
- description = " data centers that the job runs in"
9
+ description = " Data centers that the job is eligible to run in"
10
10
type = list (string )
11
11
}
12
12
13
13
variable "namespace" {
14
- description = " namespace that the job runs in"
14
+ description = " Namespace that the job runs in"
15
15
type = string
16
16
default = " default"
17
17
}
18
18
19
19
variable "hosts" {
20
- description = " host constraint for the job"
20
+ description = " Host constraint for the job, if empty exactly one allocation will be created "
21
21
type = list (string )
22
22
default = []
23
23
}
@@ -80,6 +80,16 @@ variable "anonymous_role" {
80
80
default = " Viewer"
81
81
}
82
82
83
+ // /////////////////////////////////////////////////////////////////////////////
84
+ // LOCALS
85
+
86
+ locals {
87
+ logs_path = " ${ NOMAD_ALLOC_DIR } /logs"
88
+ data_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"
90
+ provisioning_path = var. data == " " ? " ${ NOMAD_ALLOC_DIR } /data/provisioning" : " /var/lib/grafana/provisioning"
91
+ }
92
+
83
93
// /////////////////////////////////////////////////////////////////////////////
84
94
// JOB
85
95
@@ -97,12 +107,15 @@ job "grafana" {
97
107
// ///////////////////////////////////////////////////////////////////////////////
98
108
99
109
group "grafana" {
100
- count = length (var. hosts )
101
-
102
- constraint {
103
- attribute = node. unique . name
104
- operator = " set_contains_any"
105
- value = join (" ," , var. hosts )
110
+ count = length (var. hosts ) == 0 ? 1 : length (var. hosts )
111
+
112
+ dynamic "constraint" {
113
+ for_each = length (var. hosts ) == 0 ? [] : [ join (" ," , var. hosts ) ]
114
+ content {
115
+ attribute = node. unique . name
116
+ operator = " set_contains_any"
117
+ value = constraint. value
118
+ }
106
119
}
107
120
108
121
network {
@@ -127,10 +140,10 @@ job "grafana" {
127
140
driver = " docker"
128
141
129
142
env {
130
- GF_PATHS_LOGS = " ${ NOMAD_ALLOC_DIR } /logs "
131
- GF_PATHS_DATA = var . data == " " ? " ${ NOMAD_ALLOC_DIR } /data/db " : " /var/lib/grafana/data "
132
- GF_PATHS_PLUGINS = var . data == " " ? " ${ NOMAD_ALLOC_DIR } /data/plugins " : " /var/lib/grafana/plugins "
133
- GF_PATHS_PROVISIONING = var . data == " " ? " ${ NOMAD_ALLOC_DIR } /data/provisioning " : " /var/lib/grafana/provisioning "
143
+ GF_PATHS_LOGS = local . logs_path
144
+ GF_PATHS_DATA = local . data_path
145
+ GF_PATHS_PLUGINS = local . plugins_path
146
+ GF_PATHS_PROVISIONING = local . provisioning_path
134
147
GF_SECURITY_ADMIN_USER = " admin"
135
148
GF_SECURITY_ADMIN_PASSWORD = var. admin_password
136
149
GF_SECURITY_ADMIN_EMAIL = var. admin_email
0 commit comments