-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.tf
298 lines (250 loc) · 8.78 KB
/
deployment.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
locals {
main_container_name = "main"
command = length(var.command) > 0 ? var.command : null
}
resource "kubernetes_deployment_v1" "this" {
#bridgecrew:skip=CKV_K8S_35: "Prefer using secrets as files over secrets as environment variables". Secrets are provided as env vars for easier integration.
#bridgecrew:skip=CKV_K8S_43: "Image should use digest". Image digest is not available yet.
wait_for_rollout = false
depends_on = [kubernetes_manifest.secrets_from_gsm]
metadata {
name = local.app_name
namespace = local.app_namespace
labels = local.app_labels
}
# Pods specs
spec {
replicas = var.replicas
selector {
match_labels = local.match_labels
}
template {
metadata {
labels = local.app_labels
}
spec {
restart_policy = "Always"
service_account_name = kubernetes_service_account_v1.app.metadata[0].name
dynamic "volume" {
for_each = local.volumes
content {
name = volume.value.name
dynamic "empty_dir" {
for_each = volume.value.empty_dir == null ? [] : [1]
content {}
}
dynamic "persistent_volume_claim" {
for_each = volume.value.persistent_volume_claim == null ? [] : [volume.value.persistent_volume_claim]
iterator = pvc
content {
claim_name = pvc.value.claim_name
read_only = lookup(pvc.value, "read_only", null)
}
}
dynamic "host_path" {
for_each = volume.value.host_path == null ? [] : [volume.value.host_path]
iterator = hp
content {
type = hp.value.type
path = hp.value.path
}
}
}
}
container {
name = local.main_container_name
image = "${local.repository_url}:${local.app_version}"
args = local.command
security_context {
capabilities {
drop = ["ALL"]
}
}
resources {
requests = {
cpu = var.cpu
memory = var.memory
}
limits = {
cpu = var.cpu
memory = var.memory
}
}
dynamic "startup_probe" {
for_each = local.startup_probes
iterator = sp
content {
initial_delay_seconds = sp.value.initial_delay_seconds
period_seconds = sp.value.period_seconds
timeout_seconds = sp.value.timeout_seconds
success_threshold = sp.value.success_threshold
failure_threshold = sp.value.failure_threshold
dynamic "exec" {
for_each = sp.value.exec
content {
command = exec.value.command
}
}
dynamic "grpc" {
for_each = sp.value.grpc
content {
port = grpc.value.port
service = lookup(grpc.value, "service", null)
}
}
dynamic "tcp_socket" {
for_each = sp.value.tcp_socket
content {
port = tcp_socket.value.port
}
}
dynamic "http_get" {
for_each = sp.value.http_get
content {
host = lookup(http_get.value, "host", null)
path = lookup(http_get.value, "path", null)
port = lookup(http_get.value, "port", null)
scheme = lookup(http_get.value, "scheme", null)
dynamic "http_header" {
for_each = coalesce(tomap(lookup(http_get.value, "http_headers", "null")), tomap({}))
content {
name = http_header.key
value = http_header.value
}
}
}
}
}
}
dynamic "readiness_probe" {
for_each = local.readiness_probes
iterator = sp
content {
initial_delay_seconds = sp.value.initial_delay_seconds
period_seconds = sp.value.period_seconds
timeout_seconds = sp.value.timeout_seconds
success_threshold = sp.value.success_threshold
failure_threshold = sp.value.failure_threshold
dynamic "exec" {
for_each = sp.value.exec
content {
command = exec.value.command
}
}
dynamic "grpc" {
for_each = sp.value.grpc
content {
port = grpc.value.port
service = lookup(grpc.value, "service", null)
}
}
dynamic "tcp_socket" {
for_each = sp.value.tcp_socket
content {
port = tcp_socket.value.port
}
}
dynamic "http_get" {
for_each = sp.value.http_get
content {
host = lookup(http_get.value, "host", null)
path = lookup(http_get.value, "path", null)
port = lookup(http_get.value, "port", null)
scheme = lookup(http_get.value, "scheme", null)
dynamic "http_header" {
for_each = coalesce(tomap(lookup(http_get.value, "http_headers", "null")), tomap({}))
content {
name = http_header.key
value = http_header.value
}
}
}
}
}
}
dynamic "liveness_probe" {
for_each = local.liveness_probes
iterator = lp
content {
initial_delay_seconds = lp.value.initial_delay_seconds
period_seconds = lp.value.period_seconds
timeout_seconds = lp.value.timeout_seconds
success_threshold = lp.value.success_threshold
failure_threshold = lp.value.failure_threshold
dynamic "exec" {
for_each = lp.value.exec
content {
command = exec.value.command
}
}
dynamic "grpc" {
for_each = lp.value.grpc
content {
port = grpc.value.port
service = lookup(grpc.value, "service", null)
}
}
dynamic "tcp_socket" {
for_each = lp.value.tcp_socket
content {
port = tcp_socket.value.port
}
}
dynamic "http_get" {
for_each = lp.value.http_get
content {
host = lookup(http_get.value, "host", null)
path = lookup(http_get.value, "path", null)
port = lookup(http_get.value, "port", null)
scheme = lookup(http_get.value, "scheme", null)
dynamic "http_header" {
for_each = coalesce(tomap(lookup(http_get.value, "http_headers", "null")), tomap({}))
content {
name = http_header.key
value = http_header.value
}
}
}
}
}
}
dynamic "port" {
for_each = var.container_port > 0 ? [var.container_port] : []
content {
container_port = port.value
}
}
dynamic "env" {
for_each = local.all_env_vars
content {
name = env.key
value = env.value
}
}
dynamic "env" {
for_each = local.secret_keys
content {
name = env.value
value_from {
secret_key_ref {
name = "${local.resource_name}-gsm-secrets"
key = env.value
}
}
}
}
dynamic "volume_mount" {
for_each = local.volume_mounts
content {
name = volume_mount.key
mount_path = volume_mount.value.mount_path
sub_path = volume_mount.value.sub_path
mount_propagation = volume_mount.value.mount_propagation
read_only = volume_mount.value.read_only
}
}
}
}
}
}
}