forked from lentidas/devops-stack-test-eks-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
318 lines (260 loc) · 9.27 KB
/
main.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
# Providers configuration
# These providers depend on the output of the respectives modules declared below.
# However, for clarity and ease of maintenance we grouped them all together in this section.
provider "kubernetes" {
host = module.eks.kubernetes_host
cluster_ca_certificate = module.eks.kubernetes_cluster_ca_certificate
token = module.eks.kubernetes_token
}
provider "helm" {
kubernetes {
host = module.eks.kubernetes_host
cluster_ca_certificate = module.eks.kubernetes_cluster_ca_certificate
token = module.eks.kubernetes_token
}
}
provider "argocd" {
server_addr = "127.0.0.1:8080"
auth_token = module.argocd_bootstrap.argocd_auth_token
insecure = true
plain_text = true
port_forward = true
port_forward_with_namespace = module.argocd_bootstrap.argocd_namespace
kubernetes {
host = module.eks.kubernetes_host
cluster_ca_certificate = module.eks.kubernetes_cluster_ca_certificate
token = module.eks.kubernetes_token
}
}
###
# Module declarations and configuration
data "aws_availability_zones" "available" {}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
name = module.eks.cluster_name
cidr = local.vpc_cidr
azs = data.aws_availability_zones.available.names
private_subnets = local.vpc_private_subnets
public_subnets = local.vpc_public_subnets
enable_nat_gateway = true
create_igw = true
enable_dns_hostnames = true
private_subnet_tags = {
"kubernetes.io/cluster/${module.eks.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}
public_subnet_tags = {
"kubernetes.io/cluster/${module.eks.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
}
}
module "eks" {
source = "git::https://github.com/camptocamp/devops-stack-module-cluster-eks?ref=v2.0.1"
cluster_name = local.cluster_name
kubernetes_version = local.cluster_version
base_domain = local.base_domain
vpc_id = module.vpc.vpc_id
private_subnet_ids = module.vpc.private_subnets
public_subnet_ids = module.vpc.public_subnets
cluster_endpoint_public_access_cidrs = ["0.0.0.0/0"]
node_groups = {
"${module.eks.cluster_name}-main" = {
instance_type = "m5a.large"
min_size = 2
max_size = 3
desired_size = 2
target_group_arns = module.eks.nlb_target_groups
},
}
create_public_nlb = true
}
module "oidc" {
source = "git::https://github.com/camptocamp/devops-stack-module-oidc-aws-cognito.git?ref=v1.0.0"
cluster_name = module.eks.cluster_name
base_domain = module.eks.base_domain
create_pool = true
user_map = {
trossel = {
username = "trossel"
email = "[email protected]"
given_name = "Tanguy"
family_name = "Rossel"
}
}
}
module "argocd_bootstrap" {
source = "git::https://github.com/camptocamp/devops-stack-module-argocd.git//bootstrap?ref=v2.1.0"
depends_on = [module.eks]
}
module "traefik" {
source = "git::https://github.com/camptocamp/devops-stack-module-traefik.git//eks?ref=v1.2.3"
cluster_name = module.eks.cluster_name
base_domain = module.eks.base_domain
argocd_namespace = module.argocd_bootstrap.argocd_namespace
enable_service_monitor = local.enable_service_monitor
dependency_ids = {
argocd = module.argocd_bootstrap.id
}
}
module "cert-manager" {
source = "git::https://github.com/camptocamp/devops-stack-module-cert-manager.git//eks?ref=v4.0.3"
cluster_name = module.eks.cluster_name
base_domain = module.eks.base_domain
argocd_namespace = module.argocd_bootstrap.argocd_namespace
enable_service_monitor = local.enable_service_monitor
cluster_oidc_issuer_url = module.eks.cluster_oidc_issuer_url
dependency_ids = {
argocd = module.argocd_bootstrap.id
}
}
# module "loki-stack" {
# source = "git::https://github.com/camptocamp/devops-stack-module-loki-stack//eks?ref=v2.0.2"
#
# argocd_namespace = module.argocd_bootstrap.argocd_namespace
#
# distributed_mode = true
#
# logs_storage = {
# bucket_id = aws_s3_bucket.loki_logs_storage.id
# region = aws_s3_bucket.loki_logs_storage.region
# iam_role_arn = module.iam_assumable_role_loki.iam_role_arn
# }
#
# dependency_ids = {
# argocd = module.argocd_bootstrap.id
# }
# }
# module "thanos" {
# source = "git::https://github.com/camptocamp/devops-stack-module-thanos.git//eks?ref=v1.0.0"
#
# cluster_name = module.eks.cluster_name
# base_domain = module.eks.base_domain
# cluster_issuer = local.cluster_issuer
# argocd_namespace = module.argocd_bootstrap.argocd_namespace
#
# metrics_storage = {
# bucket_id = aws_s3_bucket.thanos_metrics_storage.id
# region = aws_s3_bucket.thanos_metrics_storage.region
# iam_role_arn = module.iam_assumable_role_thanos.iam_role_arn
# }
# thanos = {
# oidc = module.oidc.oidc
# }
#
# dependency_ids = {
# argocd = module.argocd_bootstrap.id
# traefik = module.traefik.id
# cert-manager = module.cert-manager.id
# oidc = module.oidc.id
# }
# }
module "kube-prometheus-stack" {
source = "git::https://github.com/camptocamp/devops-stack-module-kube-prometheus-stack.git//eks?ref=v3.2.0"
cluster_name = module.eks.cluster_name
argocd_namespace = module.argocd_bootstrap.argocd_namespace
base_domain = module.eks.base_domain
cluster_issuer = local.cluster_issuer
# metrics_storage = {
# bucket_id = aws_s3_bucket.thanos_metrics_storage.id
# region = aws_s3_bucket.thanos_metrics_storage.region
# iam_role_arn = module.iam_assumable_role_thanos.iam_role_arn
# }
prometheus = {
oidc = module.oidc.oidc
}
alertmanager = {
oidc = module.oidc.oidc
}
grafana = {
oidc = module.oidc.oidc
}
dependency_ids = {
argocd = module.argocd_bootstrap.id
traefik = module.traefik.id
cert-manager = module.cert-manager.id
oidc = module.oidc.id
# thanos = module.thanos.id
}
}
module "backup" {
# source = "git::https://github.com/camptocamp/devops-stack-module-backup.git//eks?ref=grafana"
source = "../module-backup/eks"
target_revision = "grafana"
cluster_name = local.cluster_name
base_domain = local.base_domain
argocd_namespace = module.argocd_bootstrap.argocd_namespace
enable_monitoring_dashboard = true
backup_schedules = {
snapshot-backup = {
disabled = false
schedule = "* 4 * * *"
template = {
# storageLocation = "backup-bucket"
includedNamespaces = ["wordpress"]
includedResources = ["persistentVolumes", "persistentVolumeClaims"]
}
},
restic-backup = {
disabled = false
schedule = "* * * * 1"
template = {
# storageLocation = "backup-bucket"
includedNamespaces = ["wordpress", "velero"]
includedResources = ["persistentVolumes", "persistentVolumeClaims", "pods"]
}
}
}
default_backup_storage = {
bucket_id = aws_s3_bucket.velero_backup_storage.id
region = aws_s3_bucket.velero_backup_storage.region
iam_role_arn = module.iam_assumable_role_velero.iam_role_arn
}
dependency_ids = {
kube-prometheus-stack = module.kube-prometheus-stack.id,
argocd = module.argocd_bootstrap.id # TODO Can cause issues on the first cluster bootstrap. If it's the case, deploy after the last argocd.
}
}
module "argocd" {
source = "git::https://github.com/camptocamp/devops-stack-module-argocd.git?ref=v2.1.0"
cluster_name = module.eks.cluster_name
base_domain = module.eks.base_domain
cluster_issuer = local.cluster_issuer
admin_enabled = "true"
namespace = module.argocd_bootstrap.argocd_namespace
accounts_pipeline_tokens = module.argocd_bootstrap.argocd_accounts_pipeline_tokens
server_secretkey = module.argocd_bootstrap.argocd_server_secretkey
oidc = {
name = "OIDC"
issuer = module.oidc.oidc.issuer_url
clientID = module.oidc.oidc.client_id
clientSecret = module.oidc.oidc.client_secret
requestedIDTokenClaims = {
groups = {
essential = true
}
}
requestedScopes = [
"openid", "profile", "email"
]
}
dependency_ids = {
argocd = module.argocd_bootstrap.id
traefik = module.traefik.id
cert-manager = module.cert-manager.id
oidc = module.oidc.id
kube-prometheus-stack = module.kube-prometheus-stack.id
}
}
module "metrics_server" {
source = "git::https://github.com/camptocamp/devops-stack-module-application.git?ref=v1.2.2"
name = "metrics-server"
argocd_namespace = module.argocd_bootstrap.argocd_namespace
source_repo = "https://github.com/kubernetes-sigs/metrics-server.git"
source_repo_path = "charts/metrics-server"
source_target_revision = "metrics-server-helm-chart-3.8.3"
destination_namespace = "kube-system"
dependency_ids = {
argocd = module.argocd.id
}
}