Skip to content

Commit 37b9e2b

Browse files
committed
Updates
1 parent 20983a5 commit 37b9e2b

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

grafana/nomad/grafana.hcl

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
// VARIABLES
77

88
variable "dc" {
9-
description = "data centers that the job runs in"
9+
description = "Data centers that the job is eligible to run in"
1010
type = list(string)
1111
}
1212

1313
variable "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

1919
variable "hosts" {
20-
description = "host constraint for the job"
20+
description = "Host constraint for the job, if empty exactly one allocation will be created"
2121
type = list(string)
2222
default = []
2323
}
@@ -80,6 +80,16 @@ variable "anonymous_role" {
8080
default = "Viewer"
8181
}
8282

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+
8393
///////////////////////////////////////////////////////////////////////////////
8494
// JOB
8595

@@ -97,12 +107,15 @@ job "grafana" {
97107
/////////////////////////////////////////////////////////////////////////////////
98108

99109
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+
}
106119
}
107120

108121
network {
@@ -127,10 +140,10 @@ job "grafana" {
127140
driver = "docker"
128141

129142
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
134147
GF_SECURITY_ADMIN_USER = "admin"
135148
GF_SECURITY_ADMIN_PASSWORD = var.admin_password
136149
GF_SECURITY_ADMIN_EMAIL = var.admin_email

influxdb/input.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ variable "docker_tag" {
2424

2525
variable "hosts" {
2626
type = list(string)
27-
description = "List of hosts to deploy on (required)"
27+
description = "List of hosts to deploy on. If empty, one allocation will be created"
28+
default = []
2829
}
2930

3031
variable "port" {

postgresql/input.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ variable "docker_tag" {
2424

2525
variable "hosts" {
2626
type = list(string)
27-
description = "List of hosts to deploy on (required)"
27+
description = "List of hosts to deploy on, if not specified deploys to one node"
28+
default = []
2829
}
2930

3031
variable "port" {

postgresql/nomad/postgresql.hcl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ job "postgresql" {
8585
/////////////////////////////////////////////////////////////////////////////////
8686

8787
group "postgresql" {
88-
count = length(var.hosts)
89-
90-
constraint {
91-
attribute = node.unique.name
92-
operator = "set_contains_any"
93-
value = join(",", var.hosts)
88+
count = length(var.hosts) == 0 ? 1 : length(var.hosts)
89+
90+
dynamic "constraint" {
91+
for_each = length(var.hosts) == 0 ? [] : [ join(",", var.hosts) ]
92+
content {
93+
attribute = node.unique.name
94+
operator = "set_contains_any"
95+
value = constraint.value
96+
}
9497
}
9598

9699
network {

0 commit comments

Comments
 (0)