Skip to content

Commit 273735a

Browse files
committed
Added LDAP ldif and schemas
1 parent 321fe82 commit 273735a

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

openldap/input.tf

Lines changed: 13 additions & 3 deletions
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, defaults to one host"
28+
default = []
2829
}
2930

3031
variable "port" {
@@ -35,8 +36,17 @@ variable "port" {
3536

3637
variable "data" {
3738
type = string
38-
description = "Directory for data persistence"
39-
default = ""
39+
description = "Directory for data persistence, required"
40+
}
41+
42+
variable "ldif" {
43+
type = string
44+
description = "Directory for additional ldif files, optional"
45+
}
46+
47+
variable "schema" {
48+
type = string
49+
description = "Directory for additional schema files, optional"
4050
}
4151

4252
variable "admin_password" {

openldap/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ resource "nomad_job" "ldap" {
1313
hosts = jsonencode(var.hosts)
1414
port = var.port
1515
data = var.data
16+
ldif = var.ldif
17+
schema = var.schema
1618
admin_password = var.admin_password
1719
basedn = var.basedn
1820
}

openldap/nomad/openldap.hcl

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ variable "port" {
4646
}
4747

4848
variable "data" {
49-
description = "Data persistence directory"
49+
description = "Data persistence directory, required"
50+
type = string
51+
}
52+
53+
variable "ldif" {
54+
description = "Path to custom LDIF files, optional"
55+
type = string
56+
}
57+
58+
variable "schema" {
59+
description = "Path to custom schema files, optional"
5060
type = string
5161
}
5262

@@ -60,6 +70,15 @@ variable "basedn" {
6070
type = string
6171
}
6272

73+
///////////////////////////////////////////////////////////////////////////////
74+
// LOCALS
75+
76+
locals {
77+
data_path = "/bitnami/openldap"
78+
ldif_path = var.ldif == "" ? "" : "/ldap/ldif"
79+
schema_path = var.schema == "" ? "" : "/ldap/schema"
80+
}
81+
6382
///////////////////////////////////////////////////////////////////////////////
6483
// JOB
6584

@@ -77,12 +96,15 @@ job "openldap" {
7796
/////////////////////////////////////////////////////////////////////////////////
7897

7998
group "openldap" {
80-
count = length(var.hosts)
81-
82-
constraint {
83-
attribute = node.unique.name
84-
operator = "set_contains_any"
85-
value = join(",", var.hosts)
99+
count = length(var.hosts) == 0 ? 1 : length(var.hosts)
100+
101+
dynamic "constraint" {
102+
for_each = length(var.hosts) == 0 ? [] : [join(",", var.hosts)]
103+
content {
104+
attribute = node.unique.name
105+
operator = "set_contains_any"
106+
value = constraint.value
107+
}
86108
}
87109

88110
network {
@@ -110,7 +132,8 @@ job "openldap" {
110132
image = var.docker_image
111133
force_pull = var.docker_always_pull
112134
volumes = compact([
113-
var.data == "" ? "" : format("%s:/bitnami/openldap",var.data)
135+
local.ldif_path == "" ? "" : format("%s:%s", var.ldif, local.ldif_path),
136+
local.schema_path == "" ? "" : format("%s:%s", var.schema, local.schema_path)
114137
])
115138
ports = ["ldap"]
116139
}
@@ -125,6 +148,8 @@ job "openldap" {
125148
LDAP_ADD_SCHEMAS = "yes"
126149
LDAP_EXTRA_SCHEMAS = "cosine, inetorgperson, nis"
127150
LDAP_SKIP_DEFAULT_TREE = "yes"
151+
LDAP_CUSTOM_LDIF_DIR = local.ldif_path
152+
LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
128153
}
129154

130155
} // task "daemon"

0 commit comments

Comments
 (0)