Skip to content

Commit a27e7ab

Browse files
committed
Updates for LDAP not working yet
1 parent d350b69 commit a27e7ab

File tree

5 files changed

+78
-81
lines changed

5 files changed

+78
-81
lines changed

openldap/input.tf

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ variable "data" {
3939
description = "Directory for data persistence, required"
4040
}
4141

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"
50-
}
51-
5242
variable "admin_password" {
5343
description = "LDAP admin password (required)"
5444
type = string
@@ -59,3 +49,8 @@ variable "basedn" {
5949
description = "LDAP distinguished name (required)"
6050
type = string
6151
}
52+
53+
variable "organization" {
54+
description = "Organization name (required)"
55+
type = string
56+
}

openldap/ldif/root.ldif

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# Root
3+
dn: {{ env "NOMAD_META_basedn" }}
4+
objectClass: top
5+
objectClass: organization
6+
dc: {{ env "NOMAD_META_organization" }}
7+
description: Organization
8+
9+
# Groups
10+
dn: ou={{ env "NOMAD_META_groups" }},{{ env "NOMAD_META_basedn" }}
11+
ou: {{ env "NOMAD_META_groups" }}
12+
objectClass: top
13+
objectClass: organizationalUnit
14+
description: User groups
15+
16+
# Users
17+
dn: ou={{ env "NOMAD_META_users" }},{{ env "NOMAD_META_basedn" }}
18+
ou: {{ env "NOMAD_META_users" }}
19+
objectClass: top
20+
objectClass: organizationalUnit
21+
description: Users
22+

openldap/ldif/tree.ldif

Lines changed: 0 additions & 51 deletions
This file was deleted.

openldap/main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ 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
1816
admin_password = var.admin_password
1917
basedn = var.basedn
18+
organization = var.organization
19+
ldif = jsonencode({
20+
"root" = file("${path.module}/ldif/root.ldif")
21+
})
22+
schema = jsonencode({})
2023
}
2124
}
2225
}

openldap/nomad/openldap.hcl

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ variable "data" {
5151
}
5252

5353
variable "ldif" {
54-
description = "Path to custom LDIF files, optional"
55-
type = string
54+
description = "Custom LDIF rules, optional"
55+
type = map(string)
5656
}
5757

5858
variable "schema" {
59-
description = "Path to custom schema files, optional"
60-
type = string
59+
description = "Custom schemas, optional"
60+
type = map(string)
6161
}
6262

6363
variable "admin_password" {
@@ -70,13 +70,18 @@ variable "basedn" {
7070
type = string
7171
}
7272

73+
variable "organization" {
74+
description = "Organization name"
75+
type = string
76+
}
77+
7378
///////////////////////////////////////////////////////////////////////////////
7479
// LOCALS
7580

7681
locals {
77-
data_path = "/bitnami/openldap"
78-
ldif_path = var.ldif == "" ? "" : "/ldap/ldif"
79-
schema_path = var.schema == "" ? "" : "/ldap/schema"
82+
data_path = "/bitnami/openldap/data"
83+
ldif_path = "${NOMAD_ALLOC_DIR}/data/ldif"
84+
schema_path = "${NOMAD_ALLOC_DIR}/data/schema"
8085
}
8186

8287
///////////////////////////////////////////////////////////////////////////////
@@ -128,17 +133,31 @@ job "openldap" {
128133
task "daemon" {
129134
driver = "docker"
130135

131-
config {
132-
image = var.docker_image
133-
force_pull = var.docker_always_pull
134-
volumes = compact([
135-
local.ldif_path == "" ? "" : format("%s:%s", var.ldif, local.ldif_path),
136-
local.schema_path == "" ? "" : format("%s:%s", var.schema, local.schema_path)
137-
])
138-
ports = ["ldap"]
136+
// Metadata for ldif and schema templates
137+
meta {
138+
basedn = var.basedn
139+
organization = var.organization
140+
users = "users"
141+
groups = "groups"
139142
}
140143

141-
// TODO: /bitnami/openldap should be /alloc/data when var.data is empty
144+
// LDIF templates
145+
dynamic "template" {
146+
for_each = var.ldif
147+
content {
148+
destination = "${local.ldif_path}/${template.key}.ldif"
149+
data = template.value
150+
}
151+
}
152+
153+
// Schema templates
154+
dynamic "template" {
155+
for_each = var.schema
156+
content {
157+
destination = "${local.schema_path}/${template.key}.schema"
158+
data = template.value
159+
}
160+
}
142161

143162
env {
144163
LDAP_ADMIN_USERNAME = "admin"
@@ -148,8 +167,17 @@ job "openldap" {
148167
LDAP_ADD_SCHEMAS = "yes"
149168
LDAP_EXTRA_SCHEMAS = "cosine, inetorgperson, nis"
150169
LDAP_SKIP_DEFAULT_TREE = "yes"
151-
LDAP_CUSTOM_LDIF_DIR = local.ldif_path
152-
LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
170+
LDAP_CUSTOM_LDIF_DIR = "" // local.ldif_path
171+
LDAP_CUSTOM_SCHEMA_DIR = "" // local.schema_path
172+
}
173+
174+
config {
175+
image = var.docker_image
176+
force_pull = var.docker_always_pull
177+
volumes = compact([
178+
format("%s:%s", var.data, local.data_path),
179+
])
180+
ports = ["ldap"]
153181
}
154182

155183
} // task "daemon"

0 commit comments

Comments
 (0)