-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathargo.tf
367 lines (346 loc) · 11.3 KB
/
argo.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# Installs and configures ArgoCD for deploying GOV.UK apps
locals {
argo_host = "argo.${local.external_dns_zone_name}"
argo_workflows_host = "argo-workflows.${local.external_dns_zone_name}"
argo_metrics_config = {
enabled = true
serviceMonitor = {
enabled = true
namespace = local.monitoring_ns
}
}
argo_environment_banner_background_colors = {
test = "#5694ca"
integration = "#ffdd00"
staging = "#f47738"
production = "#d4351c"
}
argo_environment_banner_foreground_colors = {
test = "#000000"
integration = "#000000"
staging = "#000000"
production = "#ffffff"
}
}
resource "kubernetes_namespace" "apps" {
metadata {
name = var.apps_namespace
annotations = {
"argocd.argoproj.io/sync-options" = "ServerSideApply=true"
}
labels = {
"app.kubernetes.io/managed-by" = "Terraform"
"argocd.argoproj.io/managed-by" = "cluster-services"
# https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/pod_readiness_gate/
"elbv2.k8s.aws/pod-readiness-gate-inject" = "enabled"
"pod-security.kubernetes.io/audit" = "restricted"
"pod-security.kubernetes.io/enforce" = "baseline"
"pod-security.kubernetes.io/warn" = "restricted"
}
}
}
resource "kubernetes_namespace" "licensify" {
metadata {
name = var.licensify_namespace
annotations = {
"argocd.argoproj.io/sync-options" = "ServerSideApply=true"
}
labels = {
"app.kubernetes.io/managed-by" = "Terraform"
"argocd.argoproj.io/managed-by" = "cluster-services"
# https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/pod_readiness_gate/
"elbv2.k8s.aws/pod-readiness-gate-inject" = "enabled"
"pod-security.kubernetes.io/audit" = "restricted"
"pod-security.kubernetes.io/enforce" = "restricted"
"pod-security.kubernetes.io/warn" = "restricted"
}
}
}
resource "helm_release" "argo_cd" {
chart = "argo-cd"
name = "argo-cd"
namespace = local.services_ns
create_namespace = true
repository = "https://argoproj.github.io/argo-helm"
version = "7.7.11" # TODO: Dependabot or equivalent so this doesn't get neglected.
timeout = var.helm_timeout_seconds
values = [yamlencode({
global = {
logging = {
format = "json"
level = "warn"
}
}
configs = {
cm = {
url = "https://${local.argo_host}"
"oidc.config" = yamlencode({
name = "GitHub"
issuer = "https://${local.dex_host}"
clientID = "$govuk-dex-argocd:clientID"
clientSecret = "$govuk-dex-argocd:clientSecret"
})
}
# We terminate TLS at the ALB (L7 LB inside the VPC network), so tell
# argo-cd-server not to redirect to HTTPS.
params = { "server.insecure" = true }
rbac = {
"policy.csv" = <<-EOT
g, ${var.github_read_only_team}, role:readonly
g, ${var.github_read_write_team}, role:admin
EOT
}
# Adds some hacky custom CSS that inserts an environment banner into the ArgoCD UI to make it
# easier to differentiate between environments. May break if there are major changes to the
# ArgoCD UI.
styles = templatefile("${path.module}/templates/argo-custom-css.tpl", {
env_name = title(var.govuk_environment)
env_abbreviation = upper(substr(var.govuk_environment, 0, 1))
env_background_color = local.argo_environment_banner_background_colors[var.govuk_environment]
env_foreground_color = local.argo_environment_banner_foreground_colors[var.govuk_environment]
})
}
controller = { metrics = local.argo_metrics_config }
server = {
replicas = var.desired_ha_replicas
ingress = {
enabled = true
annotations = {
"alb.ingress.kubernetes.io/group.name" = "argo"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/target-type" = "ip"
"alb.ingress.kubernetes.io/load-balancer-name" = "argo"
"alb.ingress.kubernetes.io/listen-ports" = jsonencode([{ "HTTP" : 80 }, { "HTTPS" : 443 }])
"alb.ingress.kubernetes.io/ssl-redirect" = "443"
}
labels = {}
ingressClassName = "aws-alb"
hostname = local.argo_host
tls = true
}
ingressGrpc = {
enabled = true
isAWSALB = true
annotations = {
"alb.ingress.kubernetes.io/group.name" = "argo"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/target-type" = "ip"
"alb.ingress.kubernetes.io/load-balancer-name" = "argo"
"alb.ingress.kubernetes.io/listen-ports" = jsonencode([{ "HTTP" : 80 }, { "HTTPS" : 443 }])
"alb.ingress.kubernetes.io/ssl-redirect" = "443"
}
labels = {}
ingressClassName = "aws-alb"
hostname = local.argo_host
tls = true
}
metrics = local.argo_metrics_config
}
repoServer = {
metrics = local.argo_metrics_config
replicas = var.desired_ha_replicas
}
applicationSet = { replicas = var.desired_ha_replicas }
dex = { enabled = false }
notifications = {
argocdUrl = "https://${local.argo_host}"
cm = { create = false }
secret = { create = false }
metrics = local.argo_metrics_config
}
})]
}
resource "helm_release" "argo_bootstrap" {
# Relies on CRDs
depends_on = [helm_release.argo_cd]
chart = "argo-bootstrap"
name = "argo-bootstrap"
namespace = local.services_ns
create_namespace = true
repository = "https://alphagov.github.io/govuk-helm-charts/"
version = "0.3.3" # TODO: Dependabot or equivalent so this doesn't get neglected.
timeout = var.helm_timeout_seconds
values = [yamlencode({
# TODO: This TF module should not need to know the govuk_environment, since
# there is only one per AWS account.
awsAccountId = data.aws_caller_identity.current.account_id
govukEnvironment = var.govuk_environment
argocdUrl = "https://${local.argo_host}"
argoWorkflowsUrl = "https://${local.argo_workflows_host}"
rbacTeams = {
read_only = var.github_read_only_team
read_write = var.github_read_write_team
}
iamRoleServiceAccounts = {
tagImageWorkflow = {
name = local.tag_image_service_account_name
iamRoleArn = module.tag_image_iam_role.iam_role_arn
}
}
})]
}
resource "helm_release" "argo_workflows" {
chart = "argo-workflows"
name = "argo-workflows"
namespace = local.services_ns
create_namespace = true
repository = "https://argoproj.github.io/argo-helm"
version = "0.45.2" # TODO: Dependabot or equivalent so this doesn't get neglected.
timeout = var.helm_timeout_seconds
values = [yamlencode({
controller = {
podSecurityContext = {
runAsNonRoot = true
seccompProfile = {
type = "RuntimeDefault"
}
}
securityContext = {
readOnlyRootFilesystem = true
allowPrivilegeEscalation = false
capabilities = {
drop = ["ALL"]
}
}
workflowNamespaces = concat([local.services_ns], var.argo_workflows_namespaces)
workflowDefaults = {
spec = {
# The default service account is managed by argo-services in govuk-helm-charts
serviceAccountName = "argo-workflow-default"
activeDeadlineSeconds = 7200
ttlStrategy = {
secondsAfterFailure = 259200
secondsAfterSuccess = 259200
secondsAfterCompletion = 259200
}
podGC = { strategy = "OnWorkflowSuccess" }
securityContext = {
runAsNonRoot = true
runAsUser = 1001
runAsGroup = 1001
fsGroup = 1001
seccompProfile = {
type = "RuntimeDefault"
}
}
podSpecPatch = yamlencode({
containers = [
{
name = "main"
resources = {
requests = {
cpu = "100m"
memory = "64Mi"
}
limits = {
cpu = "500m"
memory = "256Mi"
}
}
}
]
})
}
}
resources = {
requests = {
cpu = "500m"
memory = "1Gi"
}
limits = {
cpu = "1"
memory = "2Gi"
}
}
workflowWorkers = 128
replicas = var.desired_ha_replicas
}
executor = {
resources = {
requests = {
cpu = "100m"
memory = "64Mi"
}
limits = {
cpu = "500m"
memory = "512Mi"
}
}
securityContext = {
readOnlyRootFileSystem = true
allowPrivilegeEscalation = false
capabilities = {
drop = ["ALL"]
}
}
}
mainContainer = {
securityContext = {
readOnlyRootFileSystem = true
allowPrivilegeEscalation = false
capabilities = {
drop = ["ALL"]
}
}
}
workflow = {
serviceAccount = { create = false }
rbac = { create = false }
}
server = {
authModes = ["client", "sso"]
ingress = {
enabled = true
annotations = {
"alb.ingress.kubernetes.io/group.name" = "argo-workflows"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/target-type" = "ip"
"alb.ingress.kubernetes.io/load-balancer-name" = "argo-workflows"
"alb.ingress.kubernetes.io/listen-ports" = jsonencode([{ "HTTP" : 80 }, { "HTTPS" : 443 }])
"alb.ingress.kubernetes.io/ssl-redirect" = "443"
}
ingressClassName = "aws-alb"
hosts = [local.argo_workflows_host]
}
sso = {
enabled = true
issuer = "https://${local.dex_host}"
clientId = {
name = "govuk-dex-argo-workflows"
key = "clientID"
}
clientSecret = {
name = "govuk-dex-argo-workflows"
key = "clientSecret"
}
redirectUrl = "https://${local.argo_workflows_host}/oauth2/callback"
scopes = ["groups"]
rbac = { enabled = true }
}
resources = {
requests = {
cpu = "200m"
memory = "256Mi"
}
limits = {
cpu = "500m"
memory = "512Mi"
}
}
podSecurityContext = {
runAsNonRoot = true
seccompProfile = {
type = "RuntimeDefault"
}
}
securityContext = {
readOnlyRootFilesystem = true
allowPrivilegeEscalation = false
capabilities = {
drop = ["ALL"]
}
}
replicas = var.desired_ha_replicas
}
})]
}