Skip to content

Commit af5f0d7

Browse files
authored
Merge pull request #4 from mutablelogic/dev
Merge OpenLDAP switch to a different container
2 parents dfbe5ac + aacddef commit af5f0d7

38 files changed

+770
-168
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ Terraform modules for nomad clusters. In order to use these modules, please use
44
the following provider block:
55

66
```hcl
7-
terraform {
8-
required_providers {
9-
nomad = {
10-
source = "hashicorp/nomad"
11-
version = "~> 2.0.0"
12-
}
13-
}
14-
}
15-
167
provider "nomad" {
178
address = env.NOMAD_ADDR
189
region = env.NOMAD_REGION
@@ -56,6 +47,18 @@ Time-series database, which can be placed on several nodes
5647
TODO:
5748
* [ ] Add TLS support
5849

50+
51+
## mongodb
52+
53+
Document database, which can be replicated on several nodes
54+
55+
* [Documentation](https://www.mongodb.com/docs/manual/)
56+
* [Terraform Example](_examples/mongodb.tf)
57+
* [Nomad Job](mongodb/nomad/mongodb.hcl)
58+
59+
TODO:
60+
* [ ] Add TLS support
61+
5962
## mosquitto
6063

6164
MQTT broker, which can be placed on several nodes

_examples/coredns.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ module "coredns" {
99
nomad_token = local.nomad_token // Token for the Nomad server
1010

1111
// Optional parameters
12-
enabled = true
13-
hosts = ["cm3"] // Host constraint for the job
14-
port = 53 // Port to expose for plaintext connections
15-
cache_ttl = 30 // Cache TTL in seconds
16-
dns_zone = "nomad" // DNS zone to serve
12+
service_type = "system" // System or service
13+
service_dns = [ "dns1", "dns2" ] // Upstream DNS
14+
enabled = true
15+
hosts = ["server1"] // Host constraint for the job
16+
port = 53 // Port to expose for plaintext connections
17+
cache_ttl = 30 // Cache TTL in seconds
18+
dns_zone = "nomad" // DNS zone to serve
1719
}

_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/mongodb.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
// Example mongodb document database
3+
module "mongodb" {
4+
source = "github.com/mutablelogic/tf-nomad//mongodb"
5+
6+
// Required parameters
7+
dc = "datacenter" // Nomad datacenter for the cluster
8+
hosts = ["server1", "server2"] // Host constraint for the job
9+
admin_password = local.MONGODB_ADMIN_PASSWORD // Password for the 'admin' user
10+
11+
// Optional parameters
12+
enabled = true // If false, no-op
13+
namespace = "default" // Nomad namespace for the cluster
14+
docker_tag = "4.4.13" // Pull version 4.4.13 of the docker image
15+
port = 27017 // Port to expose
16+
data = "/var/lib/mongodb" // Data persistence directory
17+
replicaset_name = "rs0" // Replica set name
18+
}

_examples/openldap.tf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ module "openldap" {
44
source = "github.com/mutablelogic/tf-nomad//openldap"
55

66
// Required parameters
7-
dc = "datacenter" // Nomad datacenter for the cluster
8-
hosts = ["server1", "server2"] // Host constraint for the job
9-
basedn = "dc=mutablelogic,dc=com" // Distinquished name for the LDAP server
10-
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user
11-
data = "/var/lib/ldap" // Data persistence directory
7+
dc = "datacenter" // Nomad datacenter for the cluster
8+
hosts = ["server1", "server2"] // Host constraint for the job
9+
organization = "My Organization" // Distinquished name for the LDAP server
10+
domain = "example.com" // Domain for the LDAP server
11+
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user
12+
config_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'config' user
1213

1314
// Optional parameters
14-
enabled = true // If false, no-op
15-
namespace = "default" // Nomad namespace for the nomad job
16-
docker_tag = "latest" // Pull the latest version of the docker image every job restart
17-
port = 389 // plaintext port to expose
15+
enabled = true // If false, no-op
16+
namespace = "default" // Nomad namespace for the nomad job
17+
docker_tag = "latest" // Pull the latest version of the docker image every job restart
18+
port = 389 // plaintext port to expose
19+
replication_hosts = ["ldap://server1:389/", "ldap://server2:389/"] // LDAP urls for replication
20+
data = "/var/lib/ldap" // Directory for data persistence
1821
}

coredns/input.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ variable "service_dns" {
4040
default = []
4141
}
4242

43+
variable "service_type" {
44+
description = "Run as a service or system"
45+
type = string
46+
default = "service"
47+
}
48+
4349
variable "hosts" {
4450
type = list(string)
4551
description = "List of hosts to deploy on. If empty, one allocation will be created"
@@ -61,6 +67,7 @@ variable "nomad_token" {
6167
description = "Nomad authentication token"
6268
type = string
6369
default = ""
70+
sensitive = true
6471
}
6572

6673
variable "cache_ttl" {

coredns/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ resource "nomad_job" "coredns" {
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)
1314
service_provider = var.service_provider
1415
service_name = var.service_name
1516
service_dns = jsonencode(var.service_dns)
16-
hosts = jsonencode(var.hosts)
17+
service_type = var.service_type
18+
1719
port = var.port
1820
corefile = file("${path.module}/config/Corefile")
1921
nomad_addr = var.nomad_addr

coredns/nomad/coredns.hcl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
// coredns for service discovery
3-
// Docker Image: https://hub.docker.com/r/coredns/coredns/
3+
// Docker Image: ghcr.io/mutablelogic/coredns-nomad
44

55
///////////////////////////////////////////////////////////////////////////////
66
// VARIABLES
@@ -40,10 +40,10 @@ variable "service_dns" {
4040
default = []
4141
}
4242

43-
variable "dns_servers" {
44-
description = "Task DNS servers"
45-
type = list(string)
46-
default = []
43+
variable "service_type" {
44+
description = "Run as a service or system"
45+
type = string
46+
default = "service"
4747
}
4848

4949
variable "docker_image" {
@@ -57,6 +57,8 @@ variable "docker_always_pull" {
5757
default = false
5858
}
5959

60+
///////////////////////////////////////////////////////////////////////////////
61+
6062
variable "port" {
6163
description = "Port for plaintext connections"
6264
type = number
@@ -102,7 +104,7 @@ locals {
102104
// JOB
103105

104106
job "coredns" {
105-
type = "service"
107+
type = var.service_type
106108
datacenters = var.dc
107109
namespace = var.namespace
108110

@@ -115,7 +117,7 @@ job "coredns" {
115117
/////////////////////////////////////////////////////////////////////////////////
116118

117119
group "coredns" {
118-
count = length(var.hosts) == 0 ? 1 : length(var.hosts)
120+
count = (length(var.hosts) == 0 || var.service_type == "system") ? 1 : length(var.hosts)
119121

120122
dynamic "constraint" {
121123
for_each = length(var.hosts) == 0 ? [] : [join(",", var.hosts)]
@@ -134,7 +136,7 @@ job "coredns" {
134136
}
135137

136138
service {
137-
tags = ["dns"]
139+
tags = ["coredns", "dns"]
138140
name = var.service_name
139141
port = "dns"
140142
provider = var.service_provider
@@ -163,8 +165,8 @@ job "coredns" {
163165
image = var.docker_image
164166
force_pull = var.docker_always_pull
165167
ports = ["dns"]
166-
args = ["coredns", "-conf", local.core_file]
167168
dns_servers = var.service_dns
169+
args = ["coredns", "-conf", local.core_file]
168170
}
169171

170172
} // task "daemon"

coredns/providers.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
terraform {
3+
required_providers {
4+
nomad = {
5+
source = "hashicorp/nomad"
6+
version = "~> 2.0.0"
7+
}
8+
}
9+
}

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" {

0 commit comments

Comments
 (0)