-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvnets.tf
482 lines (449 loc) · 27.1 KB
/
vnets.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# This terraform plan defines the resources necessary to provision the Virtual
# Networks in Azure according to IEP-002:
# <https://github.com/jenkins-infra/iep/tree/master/iep-002>
#
# ┌────────────────┐ ┌───────────────────────────┐
# ┌───────────────────────┐ │ │ │ │
# │ │ │ │ │ │
# ┌─────────► Public VPN Gateway ◄─────────► Public VNet ◄─────────────────────────────►│ Public-Sponsored Vnet │
# │ │ │ │ │ VNet peering │ │
# │ └───────────────────────┘ │ IPv4 + IPv6 │◄───────────────────┐ │ │
# │ └─▲──────────▲───┘ Vnet peering │ └───────────────────────────┘
# │ │ │ │
# │ │ │
# The Internet ─────────────────────────────────────┘ VNet peering ┌─────▼──────────────┐
# │ │ │
# │ │ │ │
# │ ┌────────────▼───┐ │ Public DB │
# │ ┌───────────────────────┐ │ │◄────────────►│ │ ┌──────────────────────────┐
# │ │ │ │ │ Vnet peering │ │ │ │
# ├─────────► Private VPN Gateway ◄─────────► Private VNet │ └────────────────────┘ │ │
# │ │ │ │ │ │ InfraCi-sponsoredvnet │
# │ └───────────────────────┘ ┌──────►│ │◄──────────────────────────────────────────►│ │
# │ │ └───────▲────────┘ Vnet peering │ │
# │ │ │Vnet Peering └──────────────────────────┘
# │ │ │
# │ VNet Peering ┌────▼─────────────┐ ┌───────────────────────────┐
# │ │ │ │ │ │
# │ │ │ │ │ │
# │ │ │ │ Vnet peering │ CertCi-sponsoredVnet │
# │ │ │ Cert CI VNet ◄────────────────────────► │
# │ │ │ │ │ │
# │ │ │ │ └───────────────────────────┘
# │ │ │ │
# │ │ └──────────────────┘
# │ ▼
# │ ┌──────────────────┐
# │ ┌───────────────────────┤ │ ┌───────────────────────────┐
# │ │ │ ▼ │ │
# │ │ ┌──────────┐ │ │ │ │
# └─────────► │Bounce VM │ │ Trusted VNet │◄───────────────────────────────────►│ Trusted-sponsoredVVnet │
# │ └──────────┘ │ │ Vnet peering │ │
# │ │ │ │ │
# └───────────────────────┤ │ └───────────────────────────┘
# └──────────────────┘
#
# See also https://github.com/jenkins-infra/azure/blob/legacy-tf/plans/vnets.tf
module "public_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
base_name = "public"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.244.0.0/14", "fd00:db8:deca::/48"]
subnets = [
{
# Dedicated subnet for the "publick8s" AKS cluster resources
## Important: the "terraform-production" Enterprise Application used by this repo pipeline needs to be able to manage this virtual network.
## See the corresponding role assignment for this vnet added in the (private) terraform-state repo:
## https://github.com/jenkins-infra/terraform-states/blob/17df75c38040c9b1087bade3654391bc5db45ffd/azure/main.tf#L59
name = "publick8s-tier"
address_prefixes = [
"10.245.0.0/24", # 10.245.0.1 - 10.245.0.254
"fd00:db8:deca:deed::/64", # smaller size as we're using kubenet (required by dual-stack AKS cluster), which allocate one IP per node instead of one IP per pod (in case of Azure CNI)
]
service_endpoints = ["Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = false
private_endpoint_network_policies = "Enabled"
},
{
# Dedicated subnet for machine to machine private communications
name = "public-vnet-data-tier"
address_prefixes = ["10.245.1.0/24"] # 10.245.1.1 - 10.245.1.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = false
private_endpoint_network_policies = "Enabled"
}
,
{
# Dedicated subnets for ci.jenkins.io (controller and agents)
name = "public-vnet-ci_jenkins_io_agents"
address_prefixes = ["10.245.2.0/23"] # 10.245.2.1 - 10.245.3.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
}
,
{
# Dedicated subnets for ci.jenkins.io (controller and agents)
name = "public-vnet-ci_jenkins_io_controller"
address_prefixes = [
"10.245.4.0/24", # 10.245.4.1 - 10.245.4.254
"fd00:db8:deca::/64",
]
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
}
]
peered_vnets = {
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id,
"${module.public_db_vnet.vnet_name}" = module.public_db_vnet.vnet_id,
"${module.public_sponsorship_vnet.vnet_name}" = module.public_sponsorship_vnet.vnet_id,
}
}
module "private_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
base_name = "private"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.248.0.0/14"] # 10.248.0.1 - 10.251.255.254
subnets = [
{
# Dedicated subnet for external access (such as VPN external NIC)
name = "private-vnet-dmz"
address_prefixes = ["10.248.0.0/28"]
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
# Dedicated subnet for machine to machine private communications
name = "private-vnet-data-tier"
address_prefixes = ["10.248.1.0/24"] # 10.248.1.0 - 10.248.1.255
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
# Dedicated subnet for the "privatek8s" AKS cluster resources
## Important: the "terraform-production" Enterprise Application used by this repo pipeline needs to be able to manage this virtual network.
## See the corresponding role assignment for this vnet added in the (private) terraform-state repo:
## https://github.com/jenkins-infra/terraform-states/blob/17df75c38040c9b1087bade3654391bc5db45ffd/azure/main.tf#L59
name = "privatek8s-tier"
address_prefixes = ["10.249.0.0/16"]
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
# Dedicated subnet for the release nodes of the "privatek8s" AKS cluster resources
## Important: the "terraform-production" Enterprise Application used by this repo pipeline needs to be able to manage this virtual network.
## See the corresponding role assignment for this vnet added in the (private) terraform-state repo:
## https://github.com/jenkins-infra/terraform-states/blob/17df75c38040c9b1087bade3654391bc5db45ffd/azure/main.tf#L59
name = "privatek8s-release-tier"
address_prefixes = ["10.250.0.0/25"] # from 10.250.0.0 to 10.250.0.127
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
# Dedicated subnet for the release nodes of the "privatek8s" for the controller infraci AKS cluster resources
name = "privatek8s-infraci-ctrl-tier"
address_prefixes = ["10.250.0.128/26"] # from 10.250.0.128 to 10.250.0.191
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
}
,
{
# Dedicated subnet for the private nodes of the "privatek8s" for the controller releaseci AKS cluster resources
name = "privatek8s-releaseci-ctrl-tier"
address_prefixes = ["10.250.0.192/26"] # from 10.250.0.192 to 10.250.0.255
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
}
]
peered_vnets = {
"${module.public_vnet.vnet_name}" = module.public_vnet.vnet_id,
"${module.public_db_vnet.vnet_name}" = module.public_db_vnet.vnet_id,
"${module.public_sponsorship_vnet.vnet_name}" = module.public_sponsorship_vnet.vnet_id,
"${module.cert_ci_jenkins_io_vnet.vnet_name}" = module.cert_ci_jenkins_io_vnet.vnet_id
"${module.trusted_ci_jenkins_io_vnet.vnet_name}" = module.trusted_ci_jenkins_io_vnet.vnet_id
"${module.infra_ci_jenkins_io_sponsorship_vnet.vnet_name}" = module.infra_ci_jenkins_io_sponsorship_vnet.vnet_id
}
}
module "public_sponsorship_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
providers = {
azurerm = azurerm.jenkins-sponsorship
}
base_name = "public-jenkins-sponsorship"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.200.0.0/14"]
subnets = [
{
name = "public-jenkins-sponsorship-vnet-ci_jenkins_io_agents"
address_prefixes = ["10.200.2.0/24"] # 10.200.2.1 - 10.200.2.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = false
private_endpoint_network_policies = "Disabled"
},
{
name = "public-jenkins-sponsorship-vnet-ci_jenkins_io_aci"
address_prefixes = ["10.200.3.0/24"] # 10.200.3.1 - 10.200.3.254
service_endpoints = []
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
delegations = {
"aci" = {
service_delegations = [{
name = "Microsoft.ContainerInstance/containerGroups"
actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
}]
}
}
},
{
name = "public-jenkins-sponsorship-vnet-ci_jenkins_io_controller"
address_prefixes = ["10.200.1.0/24"] # 10.200.1.1 - 10.200.1.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Disabled"
},
{
name = "public-jenkins-sponsorship-vnet-ci_jenkins_io_kubernetes"
address_prefixes = ["10.201.0.0/24"] # 10.201.0.0 - 10.201.0.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = false
private_endpoint_network_policies = "Enabled"
},
]
peered_vnets = {
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id,
"${module.public_vnet.vnet_name}" = module.public_vnet.vnet_id,
"${module.infra_ci_jenkins_io_sponsorship_vnet.vnet_name}" = module.infra_ci_jenkins_io_sponsorship_vnet.vnet_id,
}
}
module "trusted_ci_jenkins_io_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
base_name = "trusted-ci-jenkins-io"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.252.0.0/21"] # 10.252.0.1 - 10.252.7.254
subnets = [
{
name = "trusted-ci-jenkins-io-vnet-controller"
address_prefixes = ["10.252.0.0/24"] # 10.252.0.1 - 10.252.0.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
name = "trusted-ci-jenkins-io-vnet-ephemeral-agents"
address_prefixes = ["10.252.1.0/24"] # 10.252.1.1 - 10.252.1.254
service_endpoints = ["Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
name = "trusted-ci-jenkins-io-vnet-permanent-agents"
address_prefixes = ["10.252.2.0/24"] # 10.252.2.1 - 10.252.2.254
service_endpoints = ["Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Disabled"
},
]
peered_vnets = {
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id,
"${module.trusted_ci_jenkins_io_sponsorship_vnet.vnet_name}" = module.trusted_ci_jenkins_io_sponsorship_vnet.vnet_id,
}
}
module "trusted_ci_jenkins_io_sponsorship_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
providers = {
azurerm = azurerm.jenkins-sponsorship
}
base_name = "trusted-ci-jenkins-io-sponsorship"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.204.0.0/24"] # 10.204.0.1 - 10.204.0.254
subnets = [
{
name = "trusted-ci-jenkins-io-sponsorship-vnet-ephemeral-agents"
address_prefixes = ["10.204.0.0/24"] # 10.204.0.1 - 10.204.0.254
service_endpoints = ["Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
]
peered_vnets = {
"${module.trusted_ci_jenkins_io_vnet.vnet_name}" = module.trusted_ci_jenkins_io_vnet.vnet_id
}
}
module "cert_ci_jenkins_io_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
base_name = "cert-ci-jenkins-io"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.252.8.0/21"] # 10.252.8.1 - 10.252.15.254
subnets = [
{
name = "cert-ci-jenkins-io-vnet-controller"
address_prefixes = ["10.252.8.0/24"] # 10.252.8.1 - 10.252.8.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
name = "cert-ci-jenkins-io-vnet-ephemeral-agents"
address_prefixes = ["10.252.9.0/24"] # 10.252.9.1 - 10.252.9.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
]
peered_vnets = {
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id
"${module.cert_ci_jenkins_io_sponsorship_vnet.vnet_name}" = module.cert_ci_jenkins_io_sponsorship_vnet.vnet_id
}
}
module "cert_ci_jenkins_io_sponsorship_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
providers = {
azurerm = azurerm.jenkins-sponsorship
}
base_name = "cert-ci-jenkins-io-sponsorship"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.205.0.0/24"] # 10.205.0.1 - 10.205.0.254
subnets = [
{
name = "cert-ci-jenkins-io-sponsorship-vnet-ephemeral-agents"
address_prefixes = ["10.205.0.0/24"] # 10.205.0.1 - 10.205.0.254
service_endpoints = []
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
]
peered_vnets = {
"${module.cert_ci_jenkins_io_vnet.vnet_name}" = module.cert_ci_jenkins_io_vnet.vnet_id
}
}
module "infra_ci_jenkins_io_sponsorship_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
providers = {
azurerm = azurerm.jenkins-sponsorship
}
base_name = "infra-ci-jenkins-io-sponsorship"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.206.0.0/22"] # 10.206.0.1 - 10.206.3.254
subnets = [
{
name = "infra-ci-jenkins-io-sponsorship-vnet-ephemeral-agents"
address_prefixes = ["10.206.0.0/24"] # 10.206.0.1 - 10.206.0.254
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
name = "infra-ci-jenkins-io-sponsorship-vnet-packer-builds"
address_prefixes = ["10.206.1.0/24"] # 10.206.1.1 - 10.206.1.254
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
{
name = "infra-ci-jenkins-io-sponsorship-vnet-kubernetes-agents"
address_prefixes = ["10.206.2.0/24"] # 10.206.2.0 - 10.206.2.254
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
delegations = {}
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
},
]
peered_vnets = {
"${module.public_sponsorship_vnet.vnet_name}" = module.public_sponsorship_vnet.vnet_id
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id
"${module.public_db_vnet.vnet_name}" = module.public_db_vnet.vnet_id,
}
}
# separate vNET as Postgres/Mysql flexible server currently doesn't support a vNET with ipv4 and ipv6 address spaces
module "public_db_vnet" {
source = "./.shared-tools/terraform/modules/azure-full-vnet"
base_name = "public"
use_existing_rg = true
custom_vnet_name = "public-db-vnet"
tags = local.default_tags
location = var.location
vnet_address_space = ["10.253.0.0/21"] # 10.253.0.1 - 10.253.7.254
subnets = [
# This subnet is reserved as "delegated" for the pgsql server on the public-db network
# Ref. https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-networking
{
name = "public-db-vnet-postgres-tier",
address_prefixes = ["10.253.0.0/24"], # 10.253.0.1 - 10.253.0.254,
service_endpoints = [],
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled"
delegations = {
"pgsql" = {
service_delegations = [{
name = "Microsoft.DBforPostgreSQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
]
}]
}
}
},
# This subnet is reserved as "delegated" for the mysql server on the public-db network
# Ref. https://docs.microsoft.com/en-us/azure/mysql/flexible-server/concepts-networking
{
name = "public-db-vnet-mysql-tier",
address_prefixes = ["10.253.1.0/24"] # 10.253.1.1 - 10.253.1.254
service_endpoints = [],
private_link_service_network_policies_enabled = true
private_endpoint_network_policies = "Enabled",
delegations = {
"mysql" = {
service_delegations = [{
name = "Microsoft.DBforMySQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
]
}]
}
}
}
]
peered_vnets = {
"${module.infra_ci_jenkins_io_sponsorship_vnet.vnet_name}" = module.infra_ci_jenkins_io_sponsorship_vnet.vnet_id
"${module.public_vnet.vnet_name}" = module.public_vnet.vnet_id
"${module.private_vnet.vnet_name}" = module.private_vnet.vnet_id
}
}