Skip to content

Commit 308d01a

Browse files
committed
Updates
1 parent a9c1147 commit 308d01a

File tree

9 files changed

+138
-41
lines changed

9 files changed

+138
-41
lines changed

_examples/grafana.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ module "grafana" {
1313
hosts = ["server1"] // Host constraint for the job. If not specified, the job will be deployed to one node
1414
docker_tag = "latest" // Pull the latest version of the docker image every job restart
1515
port = 3000 // Port to expose
16-
data = "/var/lib/influxdb" // Data persistence directory. If not set, then data is not persisted
1716
admin_email = "admin@mutablelogic" // Email address for the admin user
1817
anonymous = false // When true, allow anonymous access as a viewer
18+
19+
// Data persistence directory. If not set, then data is not persisted. When persistence is enabled,
20+
// set user/group to 472 for the container to have write access to the data directory
21+
data = "/var/lib/grafana"
1922
}

_examples/openldap.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ module "openldap" {
88
hosts = ["server1", "server2"] // Host constraint for the job
99
basedn = "dc=mutablelogic,dc=com" // Distinquished name for the LDAP server
1010
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user
11-
data = "/var/lib/ldap" // Data persistence directory
1211

1312
// Optional parameters
1413
enabled = true // If false, no-op
1514
namespace = "default" // Nomad namespace for the nomad job
1615
docker_tag = "latest" // Pull the latest version of the docker image every job restart
1716
port = 389 // plaintext port to expose
17+
18+
// When persisting data, set uid and gid to 1000 for the container to
19+
// have write access to the data directory
20+
data = "/var/lib/ldap"
1821
}

grafana/input.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,34 @@ variable "docker_tag" {
2222
default = "latest"
2323
}
2424

25+
variable "service_provider" {
26+
description = "Service provider, either consul or nomad"
27+
type = string
28+
default = "nomad"
29+
}
30+
31+
variable "service_name" {
32+
description = "Service name"
33+
type = string
34+
default = "openldap-ldap"
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+
2549
variable "hosts" {
2650
type = list(string)
27-
description = "List of hosts to deploy on (required)"
51+
description = "List of hosts to deploy on. If empty, one allocation will be created"
52+
default = []
2853
}
2954

3055
variable "port" {

grafana/main.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ resource "nomad_job" "grafana" {
88
vars = {
99
dc = jsonencode([var.dc])
1010
namespace = var.namespace
11+
hosts = jsonencode(var.hosts)
1112
docker_image = local.docker_image
1213
docker_always_pull = jsonencode(local.docker_always_pull)
13-
hosts = jsonencode(var.hosts)
14-
port = var.port
15-
data = var.data
16-
admin_password = var.admin_password
17-
admin_email = var.admin_email
18-
anonymous_enabled = var.anonymous
19-
anonymous_org = ""
20-
anonymous_role = "Viewer"
14+
service_provider = var.service_provider
15+
service_name = var.service_name
16+
service_dns = jsonencode(var.service_dns)
17+
service_type = var.service_type
18+
19+
port = var.port
20+
data = var.data
21+
admin_password = var.admin_password
22+
admin_email = var.admin_email
23+
anonymous_enabled = var.anonymous
24+
anonymous_org = ""
25+
anonymous_role = "Viewer"
2126
}
2227
}
2328
}

grafana/nomad/grafana.hcl

Lines changed: 33 additions & 14 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 is eligible to run 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, 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+
3149
variable "docker_image" {
3250
description = "Docker image"
3351
type = string
@@ -39,6 +57,8 @@ variable "docker_always_pull" {
3957
default = false
4058
}
4159

60+
///////////////////////////////////////////////////////////////////////////////
61+
4262
variable "port" {
4363
description = "Port for plaintext connections"
4464
type = number
@@ -84,17 +104,17 @@ variable "anonymous_role" {
84104
// LOCALS
85105

86106
locals {
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

96116
job "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"

nginx/input.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,28 @@ variable "docker_tag" {
2222
default = "latest"
2323
}
2424

25+
variable "service_provider" {
26+
description = "Service provider, either consul or nomad"
27+
type = string
28+
default = "nomad"
29+
}
30+
31+
variable "service_dns" {
32+
description = "Service discovery DNS"
33+
type = list(string)
34+
default = []
35+
}
36+
37+
variable "service_type" {
38+
description = "Run as a service or system"
39+
type = string
40+
default = "service"
41+
}
42+
2543
variable "hosts" {
2644
type = list(string)
27-
description = "List of hosts to deploy on, deploys on a single host if empty"
45+
description = "List of hosts to deploy on. If empty, one allocation will be created"
46+
default = []
2847
}
2948

3049
variable "ports" {

nginx/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ resource "nomad_job" "nginx" {
66
hcl2 {
77
allow_fs = true
88
vars = {
9-
dc = jsonencode([var.dc])
9+
dc = jsonencode([var.dc])
1010
namespace = var.namespace
11+
hosts = jsonencode(var.hosts)
1112
docker_image = local.docker_image
1213
docker_always_pull = jsonencode(local.docker_always_pull)
14+
service_provider = var.service_provider
15+
service_dns = jsonencode(var.service_dns)
16+
service_type = var.service_type
17+
1318
hosts = jsonencode(var.hosts)
1419
ports = jsonencode(var.ports)
1520
config = chomp(file("${path.module}/config/nginx.conf"))

nginx/nomad/nginx.hcl

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11

22
// nginx web server
3-
// Docker Image: grafana/grafana
3+
// Docker Image: nginx
44

55
///////////////////////////////////////////////////////////////////////////////
66
// VARIABLES
77

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

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, if empty exactly one allocation will be created"
20+
description = "List of hosts to deploy on. If empty, one allocation will be created"
2121
type = list(string)
2222
default = []
2323
}
@@ -28,10 +28,27 @@ 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+
3149
variable "docker_image" {
3250
description = "Docker image"
3351
type = string
34-
default = "nginx"
3552
}
3653

3754
variable "docker_always_pull" {
@@ -40,6 +57,8 @@ variable "docker_always_pull" {
4057
default = false
4158
}
4259

60+
///////////////////////////////////////////////////////////////////////////////
61+
4362
variable "ports" {
4463
description = "Ports to expose"
4564
type = map(number)
@@ -67,7 +86,7 @@ variable "servers" {
6786
// JOB
6887

6988
job "nginx" {
70-
type = "service"
89+
type = var.service_type
7190
datacenters = var.dc
7291
namespace = var.namespace
7392

@@ -80,7 +99,7 @@ job "nginx" {
8099
/////////////////////////////////////////////////////////////////////////////////
81100

82101
group "nginx" {
83-
count = length(var.hosts) == 0 ? 1 : length(var.hosts)
102+
count = (length(var.hosts) == 0 || var.service_type == "system") ? 1 : length(var.hosts)
84103

85104
dynamic "constraint" {
86105
for_each = length(var.hosts) == 0 ? [] : [join(",", var.hosts)]
@@ -144,14 +163,13 @@ job "nginx" {
144163
}
145164

146165
config {
147-
image = var.docker_image
148-
force_pull = var.docker_always_pull
149-
ports = keys(var.ports)
150-
args = ["nginx", "-c", "${NOMAD_TASK_DIR}/config/nginx.conf", "-g", "daemon off;"]
166+
image = var.docker_image
167+
force_pull = var.docker_always_pull
168+
ports = keys(var.ports)
169+
dns_servers = var.service_dns
170+
args = ["nginx", "-c", "${NOMAD_TASK_DIR}/config/nginx.conf", "-g", "daemon off;"]
151171
}
152172

153173
} // task "server"
154-
155174
} // group "nginx"
156-
157175
} // job "nginx"

openldap/nomad/openldap.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ job "openldap" {
191191
LDAP_EXTRA_SCHEMAS = var.extra_schemas
192192
LDAP_SKIP_DEFAULT_TREE = "yes"
193193
LDAP_CUSTOM_LDIF_DIR = local.ldif_path
194-
LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
194+
//LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
195195
LDAP_CONFIGURE_PPOLICY = "yes"
196196
LDAP_ALLOW_ANON_BINDING = "no"
197197
BITNAMI_DEBUG = "true"

0 commit comments

Comments
 (0)