-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvariables.tf
274 lines (228 loc) · 7.76 KB
/
variables.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
variable "name" {
type = string
description = "The name of the deployment. Will be used for all other resources"
}
variable "namespace" {
type = string
description = "The namespace where this deployment will live. Must exists."
}
variable "strategy" {
type = string
default = "RollingUpdate"
}
variable "max_unavailable" {
type = string
default = "25%"
}
variable "max_surge" {
type = string
default = "25%"
}
variable "image" {
type = any
description = "The image to deploy."
}
variable "replicas" {
type = number
default = 1
description = "The number of replicas."
}
variable "inject_linkerd" {
type = bool
default = false
description = "Add the necessary annotations for linkerd injection"
}
variable "host_aliases" {
type = map(list(string))
default = {}
}
variable "args" {
type = any
description = "Arguments to pass to the container"
default = {}
}
variable "command" {
type = any
description = "Command that the container will run"
default = {}
}
variable "ports" {
description = "Map of ports to expose, and associated settings."
type = any
default = {}
}
variable "environment_variables" {
description = "Map of environment variables to inject in containers."
type = any
default = {}
}
variable "annotations" {
description = "Map of annotations to add on containers."
type = map(string)
default = {}
}
variable "environment_variables_from_secret" {
description = "Map of environment variables to inject in containers, from existing secrets."
type = any
default = {}
}
variable "resources_limits" {
description = "Map of resources limits to assign to the container"
default = {
cpu = "0.2"
memory = "256Mi"
}
}
variable "resources_requests" {
description = "Map of resources requests to assign to the container"
default = {
cpu = "0.1"
memory = "128Mi"
}
}
variable "image_pull_secrets" {
type = list(string)
description = "List of image pull secrets to use with the containers"
default = []
}
variable "liveness_probes" {
description = "Map of liveness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#liveness_probe-1"
type = any
}
variable "readiness_probes" {
description = "Map of readiness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#readiness_probe-1"
type = any
}
variable "volume_mounts" {
description = "Map of volumes to mount."
type = any
default = {}
}
variable "volumes_mounts_from_config_map" {
description = "Map of volumes to mount from config maps."
type = any
default = {}
}
variable "volumes_mounts_from_secret" {
description = "Map of volumes to mount from secrets."
type = any
default = {}
}
variable "node_selector" {
description = "Map of labels and values for node selection"
type = map(string)
default = {}
}
variable "hpa" {
description = "settings for the horizontal pod autoscaler"
type = any
default = {
enabled = false
target_cpu = 80
min_replicas = 2
max_replicas = 6
}
}
variable "node_affinity" {
type = any
default = {}
}
variable "pod_affinity" {
type = any
default = {}
}
variable "pod_anti_affinity" {
type = any
default = {}
}
variable "image_pull_policy" {
type = string
default = "IfNotPresent"
description = "Pull policy for the images, see https://kubernetes.io/docs/concepts/containers/images/"
}
locals {
linkerd_annotations = {
"linkerd.io/inject" = var.inject_linkerd ? "enabled" : "disabled",
"config.linkerd.io/proxy-cpu-limit" = "0.75"
"config.linkerd.io/proxy-cpu-request" = "0.2"
"config.linkerd.io/proxy-memory-limit" = "768Mi"
"config.linkerd.io/proxy-memory-request" = "128Mi"
}
ingress_annotations = {
none = {}
traefik = {
"kubernetes.io/ingress.class" = "traefik"
/*"traefik.ingress.kubernetes.io/redirect-entry-point" = "https"
"traefik.ingress.kubernetes.io/redirect-permanent" = "true"
"ingress.kubernetes.io/ssl-redirect" = "true"
"ingress.kubernetes.io/ssl-temporary-redirect" = "false"*/
}
}
# This set of variables is to allow single containers with no "complex map" structure, to increase readability.
# This is quite complex and with a lot of "terraformisms" but it works
image = try(
{ (var.name) = tostring(var.image) },
var.image,
)
single_container = can(tostring(var.image))
args = try(
{ (var.name) = tolist(var.args) },
var.args
)
command = try(
{ (var.name) = tolist(var.command) },
var.command
)
ports = try(local.single_container ? { (var.name) = var.ports } : tomap(false), var.ports)
readiness_probes = try(local.single_container ? { (var.name) = var.readiness_probes } : tomap(false), var.readiness_probes)
liveness_probes = try(local.single_container ? { (var.name) = var.liveness_probes } : tomap(false), var.liveness_probes)
environment_variables_from_secret = try(local.single_container ? { (var.name) = var.environment_variables_from_secret } : tomap(false), var.environment_variables_from_secret)
annotations = try(var.inject_linkerd ? merge(local.linkerd_annotations, var.annotations) : var.annotations)
environment_variables = try(local.single_container ? { (var.name) = var.environment_variables } : tomap(false), var.environment_variables)
resources_requests = try(local.single_container ? { (var.name) = var.resources_requests } : tomap(false), var.resources_requests)
resources_limits = try(local.single_container ? { (var.name) = var.resources_limits } : tomap(false), var.resources_limits)
volume_mounts = try(local.single_container ? { (var.name) = var.volume_mounts } : tomap(false), var.volume_mounts)
volumes_mounts_from_config_map = try(local.single_container ? { (var.name) = var.volumes_mounts_from_config_map } : tomap(false), var.volumes_mounts_from_config_map)
volumes_mounts_from_secret = try(local.single_container ? { (var.name) = var.volumes_mounts_from_secret } : tomap(false), var.volumes_mounts_from_secret)
# This set of variables merges all containers ports and volumes to assign them to the pod
ports_list = flatten([
for container, portmap in local.ports : [
for port, content in portmap : {
"${container}-${port}" = merge(content, { "port" = port })
}
]
])
ports_map = { for item in local.ports_list :
keys(item)[0] => values(item)[0]
}
volumes_list = flatten([
for container, volume_map in local.volume_mounts : [
for volume, content in volume_map : {
"${container}-${volume}" = volume
}
]
])
volumes_map = { for item in local.volumes_list :
keys(item)[0] => values(item)[0]
}
volumes_from_config_map_list = flatten([
for container, volume_map in local.volumes_mounts_from_config_map : [
for volume, content in volume_map : {
"${container}-${volume}" = volume
}
]
])
volumes_from_config_maps_map = { for item in local.volumes_from_config_map_list :
keys(item)[0] => values(item)[0]
}
volumes_from_secret_list = flatten([
for container, volume_map in local.volumes_mounts_from_secret : [
for volume, content in volume_map : {
"${container}-${volume}" = volume
}
]
])
volumes_from_secrets_map = { for item in local.volumes_from_secret_list :
keys(item)[0] => values(item)[0]
}
}