11
22// OpenLDAP server
3- // Docker Image: https://bitnami .com/stack/ openldap
3+ // Docker Image: https://github .com/osixia/docker- openldap
44
55// /////////////////////////////////////////////////////////////////////////////
66// VARIABLES
@@ -31,7 +31,7 @@ variable "service_provider" {
3131variable "service_name" {
3232 description = " Service name"
3333 type = string
34- default = " coredns-dns "
34+ default = " openldap-ldap "
3535}
3636
3737variable "service_dns" {
@@ -65,49 +65,65 @@ variable "port" {
6565 default = 389
6666}
6767
68+ variable "tls_port" {
69+ description = " Port for TLS connections"
70+ type = number
71+ default = 636
72+ }
73+
6874variable "data" {
6975 description = " Data persistence directory"
7076 type = string
7177 default = " "
7278}
7379
74- variable "ldif " {
75- description = " Custom LDIF rules, optional "
76- type = map ( string )
80+ variable "admin_password " {
81+ description = " LDAP admin password "
82+ type = string
7783}
7884
79- variable "schema " {
80- description = " Custom schemas, optional "
81- type = map ( string )
85+ variable "config_password " {
86+ description = " LDAP config password "
87+ type = string
8288}
8389
84- variable "extra_schemas" {
85- description = " Extra schemas, optional"
86- type = string
87- default = " cosine,inetorgperson"
90+ variable "replication_hosts" {
91+ description = " LDAP urls for replication"
92+ type = list (string )
8893}
8994
90- variable "admin_password " {
91- description = " LDAP admin password "
95+ variable "organization " {
96+ description = " Organization name "
9297 type = string
9398}
9499
95- variable "basedn " {
96- description = " Distinguished name "
100+ variable "domain " {
101+ description = " Organization domain "
97102 type = string
98103}
99104
100- variable "organization" {
101- description = " Organization name"
102- type = string
105+ variable "ldif" {
106+ description = " Custom LDIF rules, optional"
107+ type = map (string )
108+ }
109+
110+ variable "schema" {
111+ description = " Custom schemas, optional"
112+ type = map (string )
113+ }
114+
115+ variable "debug" {
116+ description = " Debug output"
117+ type = bool
118+ default = false
103119}
104120
105121// /////////////////////////////////////////////////////////////////////////////
106122// LOCALS
107123
108124locals {
109- ldif_path = format (" %s/data/ldif" ,NOMAD_ALLOC_DIR)
110- schema_path = format (" %s/data/schema" ,NOMAD_ALLOC_DIR)
125+ ldif_path = format (" %s/data/ldif" , NOMAD_ALLOC_DIR)
126+ schema_path = format (" %s/data/schema" , NOMAD_ALLOC_DIR)
111127}
112128
113129// /////////////////////////////////////////////////////////////////////////////
@@ -143,6 +159,10 @@ job "openldap" {
143159 static = var. port
144160 to = 389
145161 }
162+ port "ldaps" {
163+ static = var. tls_port
164+ to = 636
165+ }
146166 }
147167
148168 service {
@@ -154,12 +174,12 @@ job "openldap" {
154174
155175 task "daemon" {
156176 driver = " docker"
157- user = " root"
158177
159178 // Metadata for ldif and schema templates
160179 meta {
161- basedn = var. basedn
162180 organization = var. organization
181+ domain = " {{ LDAP_DOMAIN }}"
182+ basedn = " {{ LDAP_BASE_DN }}"
163183 users = " users"
164184 groups = " groups"
165185 }
@@ -183,27 +203,27 @@ job "openldap" {
183203 }
184204
185205 env {
186- LDAP_ADMIN_USERNAME = " admin"
187- LDAP_ADMIN_PASSWORD = var. admin_password
188- LDAP_PORT_NUMBER = NOMAD_PORT_ldap
189- LDAP_ROOT = var. basedn
190- LDAP_ADD_SCHEMAS = var. extra_schemas == " " ? " no" : " yes"
191- LDAP_EXTRA_SCHEMAS = var. extra_schemas
192- LDAP_SKIP_DEFAULT_TREE = " yes"
193- LDAP_CUSTOM_LDIF_DIR = local. ldif_path
194- // LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
195- LDAP_CONFIGURE_PPOLICY = " yes"
196- LDAP_ALLOW_ANON_BINDING = " no"
197- BITNAMI_DEBUG = " true"
206+ LDAP_DOMAIN = var. domain
207+ LDAP_ORGANISATION = var. organization
208+ LDAP_ADMIN_PASSWORD = var. admin_password
209+ LDAP_CONFIG_PASSWORD = var. config_password
210+ LDAP_RFC2307BIS_SCHEMA = " true"
211+ LDAP_REMOVE_CONFIG_AFTER_SETUP = " false"
212+ LDAP_SEED_INTERNAL_LDIF_PATH = length (var. ldif ) == 0 ? " " : local. ldif_path
213+ LDAP_SEED_INTERNAL_SCHEMA_PATH = length (var. schema ) == 0 ? " " : local. schema_path
214+ LDAP_REPLICATION_HOSTS = length (var. replication_hosts ) == 0 ? " " : format (" #PYTHON2BASH:%s" , jsonencode (var. replication_hosts ))
215+ LDAP_TLS = " false"
198216 }
199217
200218 config {
201219 image = var. docker_image
202220 force_pull = var. docker_always_pull
203- ports = [" ldap" ]
221+ ports = [" ldap" , " ldaps " ]
204222 dns_servers = var. service_dns
223+ args = [" --copy-service" , " --loglevel" , var . debug ? " debug" : " info" ]
205224 volumes = compact ([
206- var . data == " " ? " " : format (" %s:/bitnami/openldap" , var. data ),
225+ var . data == " " ? " " : format (" %s/data:/var/lib/ldap" , var. data ),
226+ var . data == " " ? " " : format (" %s/slapd.d:/etc/ldap/slapd.d" , var. data ),
207227 ])
208228 }
209229
0 commit comments