forked from jenkins-infra/azure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrusted.ci.jenkins.io.tf
480 lines (441 loc) · 27.4 KB
/
trusted.ci.jenkins.io.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
resource "azurerm_private_dns_zone" "trusted" {
name = "trusted.ci.jenkins.io"
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "trusted" {
name = "trusted-vnet"
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
private_dns_zone_name = azurerm_private_dns_zone.trusted.name
virtual_network_id = data.azurerm_virtual_network.trusted_ci_jenkins_io.id
}
####################################################################################
## Resources for the Controller VM
####################################################################################
module "trusted_ci_jenkins_io" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-controller"
providers = {
azurerm = azurerm
azurerm.dns = azurerm
azuread = azuread
}
service_fqdn = azurerm_private_dns_zone.trusted.name
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
admin_username = local.admin_username
admin_ssh_publickey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ=="
controller_network_name = data.azurerm_virtual_network.trusted_ci_jenkins_io.name
controller_network_rg_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
controller_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_controller.name
controller_data_disk_size_gb = 128
controller_vm_size = "Standard_D2as_v5"
default_tags = local.default_tags
controller_resourcegroup_name = "jenkinsinfra-trusted-ci-controller"
controller_datadisk_name = "trusted-ci-controller-data-disk"
jenkins_infra_ips = {
ldap_ipv4 = azurerm_public_ip.ldap_jenkins_io_ipv4.ip_address
puppet_ipv4 = azurerm_public_ip.puppet_jenkins_io.ip_address
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
controller_service_principal_ids = [
data.azuread_service_principal.terraform_production.id,
]
controller_service_principal_end_date = "2024-09-02T00:00:00Z"
controller_packer_rg_ids = [
azurerm_resource_group.packer_images["prod"].id
]
agent_ip_prefixes = concat(
data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefixes,
data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.address_prefixes,
[azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address],
)
}
module "trusted_ci_jenkins_io_azurevm_agents" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-azurevm-agents"
custom_resourcegroup_name = "jenkinsinfra-trusted-ephemeral-agents"
service_fqdn = module.trusted_ci_jenkins_io.service_fqdn
service_short_stripped_name = module.trusted_ci_jenkins_io.service_short_stripped_name
ephemeral_agents_network_rg_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.resource_group_name
ephemeral_agents_network_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.virtual_network_name
ephemeral_agents_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.name
controller_rg_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
controller_ips = compact([module.trusted_ci_jenkins_io.controller_public_ipv4])
controller_service_principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
default_tags = local.default_tags
jenkins_infra_ips = {
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
}
# Required to allow azcopy sync of updates.jenkins.io File Share with the permanent agent
module "trusted_ci_jenkins_io_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "${module.trusted_ci_jenkins_io.service_fqdn}-fileshare_serviceprincipal_writer"
active_directory_owners = [data.azuread_service_principal.terraform_production.id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2024-06-20T19:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.updates_jenkins_io.resource_manager_id
storage_account_id = azurerm_storage_account.updates_jenkins_io.id
default_tags = local.default_tags
}
module "trustedci_updates_jenkins_io_httpd_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "${module.trusted_ci_jenkins_io.service_fqdn}-fileshare_serviceprincipal_writer-httpd"
active_directory_owners = [data.azuread_service_principal.terraform_production.id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2024-06-20T19:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.updates_jenkins_io_httpd.resource_manager_id
storage_account_id = azurerm_storage_account.updates_jenkins_io.id
default_tags = local.default_tags
}
output "trusted_ci_jenkins_io_uc_content_fileshare_client_id" {
value = module.trusted_ci_jenkins_io_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_application_client_id
}
output "trusted_ci_jenkins_io_uc_content_fileshare_client_secret" {
sensitive = true
value = module.trusted_ci_jenkins_io_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_password
}
output "trusted_ci_jenkins_io_uc_redirections_fileshare_client_id" {
value = module.trustedci_updates_jenkins_io_httpd_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_application_client_id
}
output "trusted_ci_jenkins_io_uc_redirections_fileshare_client_secret" {
sensitive = true
value = module.trustedci_updates_jenkins_io_httpd_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_password
}
# Required to allow azcopy sync of jenkins.io File Share
module "trustedci_jenkinsio_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "trustedci-jenkinsio-fileshare_serviceprincipal_writer"
active_directory_owners = [data.azuread_service_principal.terraform_production.id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2024-07-23T00:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.jenkins_io.resource_manager_id
storage_account_id = azurerm_storage_account.jenkins_io.id
default_tags = local.default_tags
}
output "trustedci_jenkinsio_fileshare_serviceprincipal_writer_application_client_id" {
value = module.trustedci_jenkinsio_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_application_client_id
}
output "trustedci_jenkinsio_fileshare_serviceprincipal_writer_password" {
sensitive = true
value = module.trustedci_jenkinsio_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_password
}
# Required to allow azcopy sync of javadoc.jenkins.io File Share
module "trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer" {
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-fileshare-serviceprincipal-writer"
service_fqdn = "trustedci-javadocjenkinsio-fileshare_serviceprincipal_writer"
active_directory_owners = [data.azuread_service_principal.terraform_production.id]
active_directory_url = "https://github.com/jenkins-infra/azure"
service_principal_end_date = "2024-07-28T00:00:00Z"
file_share_resource_manager_id = azurerm_storage_share.javadoc_jenkins_io.resource_manager_id
storage_account_id = azurerm_storage_account.javadoc_jenkins_io.id
default_tags = local.default_tags
}
output "trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer_application_client_id" {
value = module.trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_application_client_id
}
output "trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer_password" {
sensitive = true
value = module.trustedci_javadocjenkinsio_fileshare_serviceprincipal_writer.fileshare_serviceprincipal_writer_password
}
## Sponsorship subscription specific resources for controller
resource "azurerm_resource_group" "trusted_ci_jenkins_io_controller_jenkins_sponsorship" {
provider = azurerm.jenkins-sponsorship
name = module.trusted_ci_jenkins_io.controller_resourcegroup_name # Same name on both subscriptions
location = var.location
tags = local.default_tags
}
# Required to allow controller to check for subnets inside the sponsorship network
resource "azurerm_role_definition" "trusted_ci_jenkins_io_controller_vnet_sponsorship_reader" {
provider = azurerm.jenkins-sponsorship
name = "Read-trusted-ci-jenkins-io-sponsorship-VNET"
scope = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.id
permissions {
actions = ["Microsoft.Network/virtualNetworks/read"]
}
}
resource "azurerm_role_assignment" "trusted_controller_vnet_reader" {
provider = azurerm.jenkins-sponsorship
scope = data.azurerm_virtual_network.trusted_ci_jenkins_io_sponsorship.id
role_definition_id = azurerm_role_definition.trusted_ci_jenkins_io_controller_vnet_sponsorship_reader.role_definition_resource_id
principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
}
module "trusted_ci_jenkins_io_azurevm_agents_jenkins_sponsorship" {
providers = {
azurerm = azurerm.jenkins-sponsorship
}
source = "./.shared-tools/terraform/modules/azure-jenkinsinfra-azurevm-agents"
service_fqdn = module.trusted_ci_jenkins_io.service_fqdn
service_short_stripped_name = module.trusted_ci_jenkins_io.service_short_stripped_name
ephemeral_agents_network_rg_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.resource_group_name
ephemeral_agents_network_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.virtual_network_name
ephemeral_agents_subnet_name = data.azurerm_subnet.trusted_ci_jenkins_io_sponsorship_ephemeral_agents.name
controller_rg_name = azurerm_resource_group.trusted_ci_jenkins_io_controller_jenkins_sponsorship.name
controller_ips = compact([module.trusted_ci_jenkins_io.controller_public_ipv4])
controller_service_principal_id = module.trusted_ci_jenkins_io.controller_service_principal_id
default_tags = local.default_tags
storage_account_name = "trustedciagentssub" # Max 24 chars
jenkins_infra_ips = {
privatevpn_subnet = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
}
}
resource "azurerm_private_dns_a_record" "trusted_ci_controller" {
name = "@"
zone_name = azurerm_private_dns_zone.trusted.name
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
ttl = 300
records = [module.trusted_ci_jenkins_io.controller_private_ipv4]
}
####################################################################################
## Resources for the bounce (SSH bastion) VM
####################################################################################
resource "azurerm_network_interface" "trusted_bounce" {
name = "bounce.${azurerm_private_dns_zone.trusted.name}"
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
tags = local.default_tags
ip_configuration {
name = "external"
private_ip_address_allocation = "Dynamic"
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_controller.id
}
}
resource "azurerm_linux_virtual_machine" "trusted_bounce" {
name = "bounce.${azurerm_private_dns_zone.trusted.name}"
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
location = data.azurerm_virtual_network.trusted_ci_jenkins_io.location
size = "Standard_B1s"
admin_username = local.admin_username
disable_password_authentication = true
network_interface_ids = [
azurerm_network_interface.trusted_bounce.id,
]
admin_ssh_key {
username = local.admin_username
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ=="
}
user_data = base64encode(templatefile("./.shared-tools/terraform/cloudinit.tftpl", { hostname = "bounce.${azurerm_private_dns_zone.trusted.name}" }))
computer_name = "bounce.${azurerm_private_dns_zone.trusted.name}"
# Encrypt all disks (ephemeral, temp dirs and data volumes) - https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell
encryption_at_host_enabled = true
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS" # Use HDD (cheaper than SSD) as this machine does not need performances
disk_size_gb = 32 # Minimal size for ubuntu 22.04 image
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-minimal-jammy"
sku = "minimal-22_04-lts-gen2"
version = "latest"
}
}
####################################################################################
## Resources for the permanent agent VM
####################################################################################
resource "azurerm_resource_group" "trusted_ci_jenkins_io_permanent_agents" {
name = "jenkinsinfra-trusted-permanent-agents"
location = var.location
tags = local.default_tags
}
resource "azurerm_network_interface" "trusted_permanent_agent" {
name = "agent.${azurerm_private_dns_zone.trusted.name}"
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
tags = local.default_tags
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_linux_virtual_machine" "trusted_permanent_agent" {
name = "agent.${azurerm_private_dns_zone.trusted.name}"
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
tags = local.default_tags
size = "Standard_D2as_v5"
admin_username = local.admin_username
disable_password_authentication = true
network_interface_ids = [
azurerm_network_interface.trusted_permanent_agent.id,
]
admin_ssh_key {
username = local.admin_username
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5K7Ro7jBl5Kc68RdzG6EXHstIBFSxO5Da8SQJSMeCbb4cHTYuBBH8jNsAFcnkN64kEu+YhmlxaWEVEIrPgfGfs13ZL7v9p+Nt76tsz6gnVdAy2zCz607pAWe7p4bBn6T9zdZcBSnvjawO+8t/5ue4ngcfAjanN5OsOgLeD6yqVyP8YTERjW78jvp2TFrIYmgWMI5ES1ln32PQmRZwc1eAOsyGJW/YIBdOxaSkZ41qUvb9b3dCorGuCovpSK2EeNphjLPpVX/NRpVY4YlDqAcTCdLdDrEeVqkiA/VDCYNhudZTDa8f1iHwBE/GEtlKmoO6dxJ5LAkRk3RIVHYrmI6XXSw5l0tHhW5D12MNwzUfDxQEzBpGK5iSfOBt5zJ5OiI9ftnsq/GV7vCXfvMVGDLUC551P5/s/wM70QmHwhlGQNLNeJxRTvd6tL11bof3K+29ivFYUmpU17iVxYOWhkNY86WyngHU6Ux0zaczF3H6H0tpg1Ca/cFO428AVPw/RTJpcAe6OVKq5zwARNApQ/p6fJKUAdXap+PpQGZlQhPLkUbwtFXGTrpX9ePTcdzryCYjgrZouvy4ZMzruJiIbFUH8mRY3xVREVaIsJakruvgw3b14oQgcB4BwYVBBqi62xIvbRzAv7Su9t2jK6OR2z3sM/hLJRqIJ5oILMORa7XqrQ== [email protected]"
}
user_data = base64encode(templatefile("./.shared-tools/terraform/cloudinit.tftpl", { hostname = "agent.${azurerm_private_dns_zone.trusted.name}" }))
computer_name = "agent.${azurerm_private_dns_zone.trusted.name}"
# Encrypt all disks (ephemeral, temp dirs and data volumes) - https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell
encryption_at_host_enabled = true
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
disk_size_gb = "128" # existing is 100GB, but as we will pay for 128GB, let's use it
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-minimal-jammy"
sku = "minimal-22_04-lts-gen2"
version = "latest"
}
}
resource "azurerm_managed_disk" "trusted_permanent_agent_data_disk" {
name = "trusted-permanent-agent-data-disk"
location = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.location
resource_group_name = azurerm_resource_group.trusted_ci_jenkins_io_permanent_agents.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1024" # no intermediate between 512 and 1024
tags = local.default_tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "trusted_permanent_agent_data_disk" {
managed_disk_id = azurerm_managed_disk.trusted_permanent_agent_data_disk.id
virtual_machine_id = azurerm_linux_virtual_machine.trusted_permanent_agent.id
lun = "20"
caching = "ReadWrite"
}
resource "azurerm_private_dns_a_record" "trusted_permanent_agent" {
name = "agent"
zone_name = azurerm_private_dns_zone.trusted.name
resource_group_name = data.azurerm_resource_group.trusted_ci_jenkins_io.name
ttl = 300
records = [azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address]
}
####################################################################################
## Network Security Group and rules
####################################################################################
resource "azurerm_subnet_network_security_group_association" "trusted_ci_permanent_agent" {
subnet_id = data.azurerm_subnet.trusted_ci_jenkins_io_permanent_agents.id
network_security_group_id = module.trusted_ci_jenkins_io.controller_nsg_id
}
## Outbound Rules (different set of priorities than Inbound rules) ##
# Ignore the rule as it does not detect the IP restriction to only update.jenkins.io"s host
#trivy:ignore:azure-network-no-public-egress
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_permanent_agent_to_updatecenter" {
name = "allow-outbound-ssh-from-permanent-agent-to-updatecenter"
priority = 4080
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
destination_address_prefix = local.external_services["updates.${data.azurerm_dns_zone.jenkinsio.name}"]
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_from_bounce_to_controller" {
name = "allow-outbound-from-bounce-to-controller"
priority = 4090
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_port_range = "22"
destination_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_bounce_to_permanent_agent" {
name = "allow-outbound-ssh-from-bounce-to-permanent-agent"
priority = 4093
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_outbound_ssh_from_bounce_to_ephemeral_agents" {
name = "allow-outbound-ssh-from-bounce-to-ephemeral-agents"
priority = 4094
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefix
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
## Inbound Rules (different set of priorities than Outbound rules) ##
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_controller" {
name = "allow-inbound-ssh-from-bounce-to-controller"
priority = 3500
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_controller_to_permanent_agent" {
name = "allow-inbound-ssh-from-controller-to-permanent-agent"
priority = 3600
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = module.trusted_ci_jenkins_io.controller_private_ipv4
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_permanent_agent" {
name = "allow-inbound-ssh-from-bounce-to-permanent-agent"
priority = 3800
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = azurerm_linux_virtual_machine.trusted_permanent_agent.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_bounce_to_ephemeral_agents" {
name = "allow-inbound-ssh-from-bounce-to-ephemeral-agents"
priority = 3900
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
destination_address_prefix = data.azurerm_subnet.trusted_ci_jenkins_io_ephemeral_agents.address_prefix
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
#trivy:ignore:azure-network-no-public-ingress
resource "azurerm_network_security_rule" "allow_inbound_ssh_from_internet_to_bounce" {
name = "allow-inbound-ssh-from-internet-to-bounce"
priority = 4000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefixes = data.azurerm_subnet.private_vnet_data_tier.address_prefixes
destination_address_prefix = azurerm_linux_virtual_machine.trusted_bounce.private_ip_address
resource_group_name = module.trusted_ci_jenkins_io.controller_resourcegroup_name
network_security_group_name = module.trusted_ci_jenkins_io.controller_nsg_name
}
####################################################################################
## Public DNS records
####################################################################################
resource "azurerm_dns_a_record" "trusted_bounce" {
name = "bounce"
zone_name = data.azurerm_dns_zone.trusted_ci_jenkins_io.name
resource_group_name = data.azurerm_resource_group.proddns_jenkinsio.name
ttl = 60
records = [azurerm_linux_virtual_machine.trusted_bounce.private_ip_address]
tags = local.default_tags
}