@@ -46,7 +46,17 @@ variable "port" {
46
46
}
47
47
48
48
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"
50
60
type = string
51
61
}
52
62
@@ -60,6 +70,15 @@ variable "basedn" {
60
70
type = string
61
71
}
62
72
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
+
63
82
// /////////////////////////////////////////////////////////////////////////////
64
83
// JOB
65
84
@@ -77,12 +96,15 @@ job "openldap" {
77
96
// ///////////////////////////////////////////////////////////////////////////////
78
97
79
98
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
+ }
86
108
}
87
109
88
110
network {
@@ -110,7 +132,8 @@ job "openldap" {
110
132
image = var. docker_image
111
133
force_pull = var. docker_always_pull
112
134
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 )
114
137
])
115
138
ports = [" ldap" ]
116
139
}
@@ -125,6 +148,8 @@ job "openldap" {
125
148
LDAP_ADD_SCHEMAS = " yes"
126
149
LDAP_EXTRA_SCHEMAS = " cosine, inetorgperson, nis"
127
150
LDAP_SKIP_DEFAULT_TREE = " yes"
151
+ LDAP_CUSTOM_LDIF_DIR = local. ldif_path
152
+ LDAP_CUSTOM_SCHEMA_DIR = local. schema_path
128
153
}
129
154
130
155
} // task "daemon"
0 commit comments