-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompute.tf
287 lines (224 loc) · 9.21 KB
/
compute.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
resource "tls_private_key" "ssh_key" {
algorithm = "RSA"
rsa_bits = "2048"
}
resource "local_file" "ssh_key" {
sensitive_content = chomp(tls_private_key.ssh_key.private_key_pem)
filename = "${path.module}/ssh-key"
file_permission = "0600"
}
locals {
main_ip_config = "internal"
}
resource "azurerm_public_ip" "control_plane" {
count = var.control_plane_instance_count
name = "${var.prefix}-control-plane-ip-${count.index}"
resource_group_name = var.resource_group_name
location = var.location
allocation_method = "Dynamic"
tags = var.tags
}
resource "azurerm_network_interface" "control_plane" {
count = var.control_plane_instance_count
name = "${var.prefix}-control-plane-${count.index}"
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = local.main_ip_config
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.control_plane[count.index].id
}
tags = var.tags
}
resource "azurerm_public_ip" "monitoring" {
count = var.enable_monitoring ? 1 : 0
name = "${var.prefix}-monitoring-ip"
resource_group_name = var.resource_group_name
location = var.location
allocation_method = "Dynamic"
tags = var.tags
}
resource "azurerm_network_interface" "monitoring" {
count = var.enable_monitoring ? 1 : 0
name = "${var.prefix}-monitoring"
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = local.main_ip_config
subnet_id = azurerm_subnet.subnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.monitoring[count.index].id
}
tags = var.tags
}
resource "azurerm_network_interface_application_security_group_association" "control_plane" {
count = var.control_plane_instance_count
application_security_group_id = azurerm_application_security_group.control_plane.id
network_interface_id = azurerm_network_interface.control_plane[count.index].id
}
resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "control_plane" {
depends_on = [azurerm_application_gateway.this]
count = var.control_plane_instance_count
backend_address_pool_id = azurerm_application_gateway.this.backend_address_pool[0].id
ip_configuration_name = local.main_ip_config
network_interface_id = azurerm_network_interface.control_plane[count.index].id
}
resource "azurerm_network_interface_application_security_group_association" "monitoring" {
count = var.enable_monitoring ? 1 : 0
application_security_group_id = azurerm_application_security_group.worker_plane.id
network_interface_id = azurerm_network_interface.monitoring[count.index].id
}
resource "azurerm_network_interface_application_security_group_association" "monitoring_2" {
count = var.enable_monitoring ? 1 : 0
application_security_group_id = azurerm_application_security_group.monitoring.id
network_interface_id = azurerm_network_interface.monitoring[count.index].id
}
resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "monitoring" {
depends_on = [azurerm_application_gateway.this]
count = var.enable_monitoring ? 1 : 0
backend_address_pool_id = azurerm_application_gateway.this.backend_address_pool[1].id
ip_configuration_name = local.main_ip_config
network_interface_id = azurerm_network_interface.monitoring[count.index].id
}
resource "azurerm_linux_virtual_machine" "control_plane" {
count = var.control_plane_instance_count
admin_username = "centos"
admin_ssh_key {
public_key = tls_private_key.ssh_key.public_key_openssh
username = "centos"
}
location = var.location
name = "${var.prefix}-control-plane-${count.index}"
network_interface_ids = [azurerm_network_interface.control_plane[count.index].id]
resource_group_name = var.resource_group_name
size = var.control_plane_size
custom_data = module.cloud_init_control_plane.control_plane_user_data
os_disk {
caching = "None"
storage_account_type = var.control_plane_disk_root_type
disk_size_gb = var.control_plane_disk_root_size
}
source_image_id = data.azurerm_image.caravan.id
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.control_plane.id]
}
tags = var.tags
}
resource "azurerm_managed_disk" "vault_data" {
count = var.control_plane_instance_count
name = format("vault-data-%.2d", count.index + 1)
location = var.location
resource_group_name = var.resource_group_name
storage_account_type = var.control_plane_disk_data_type
create_option = "Empty"
disk_size_gb = var.control_plane_disk_data_size
tags = var.tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "vault_data" {
count = var.control_plane_instance_count
managed_disk_id = azurerm_managed_disk.vault_data[count.index].id
virtual_machine_id = azurerm_linux_virtual_machine.control_plane[count.index].id
lun = "10"
caching = "None"
}
resource "azurerm_managed_disk" "consul_data" {
count = var.control_plane_instance_count
name = format("consul-data-%.2d", count.index + 1)
location = var.location
resource_group_name = var.resource_group_name
storage_account_type = var.control_plane_disk_data_type
create_option = "Empty"
disk_size_gb = var.control_plane_disk_data_size
tags = var.tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "consul_data" {
count = var.control_plane_instance_count
managed_disk_id = azurerm_managed_disk.consul_data[count.index].id
virtual_machine_id = azurerm_linux_virtual_machine.control_plane[count.index].id
lun = "11"
caching = "None"
}
resource "azurerm_managed_disk" "nomad_data" {
count = var.control_plane_instance_count
name = format("nomad-data-%.2d", count.index + 1)
location = var.location
resource_group_name = var.resource_group_name
storage_account_type = var.control_plane_disk_data_type
create_option = "Empty"
disk_size_gb = var.control_plane_disk_data_size
tags = var.tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "nomad_data" {
count = var.control_plane_instance_count
managed_disk_id = azurerm_managed_disk.nomad_data[count.index].id
virtual_machine_id = azurerm_linux_virtual_machine.control_plane[count.index].id
lun = "12"
caching = "None"
}
resource "azurerm_linux_virtual_machine_scale_set" "worker_plane" {
depends_on = [azurerm_application_gateway.this]
admin_username = "centos"
admin_ssh_key {
public_key = tls_private_key.ssh_key.public_key_openssh
username = "centos"
}
instances = var.worker_plane_instance_count
location = var.location
name = "${var.prefix}-worker-plane"
resource_group_name = var.resource_group_name
sku = var.worker_plane_size
custom_data = module.cloud_init_worker_plane.worker_plane_user_data
network_interface {
name = "${var.prefix}-worker-plane"
primary = true
ip_configuration {
name = local.main_ip_config
subnet_id = azurerm_subnet.subnet.id
application_security_group_ids = [azurerm_application_security_group.worker_plane.id]
application_gateway_backend_address_pool_ids = [azurerm_application_gateway.this.backend_address_pool[1].id]
primary = true
public_ip_address {
name = "${var.prefix}-worker-plane-public-ip"
}
}
}
os_disk {
caching = "None"
storage_account_type = "Standard_LRS"
disk_size_gb = var.worker_plane_disk_size
}
source_image_id = data.azurerm_image.caravan.id
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.worker_plane.id]
}
tags = var.tags
}
resource "azurerm_linux_virtual_machine" "monitoring" {
depends_on = [azurerm_application_gateway.this]
count = var.enable_monitoring ? 1 : 0
admin_username = "centos"
admin_ssh_key {
public_key = tls_private_key.ssh_key.public_key_openssh
username = "centos"
}
location = var.location
name = "${var.prefix}-monitoring"
network_interface_ids = [azurerm_network_interface.monitoring[count.index].id]
resource_group_name = var.resource_group_name
size = var.monitoring_size
custom_data = module.cloud_init_worker_plane.monitoring_user_data
os_disk {
caching = "None"
storage_account_type = "Standard_LRS"
disk_size_gb = var.monitoring_disk_size
}
source_image_id = data.azurerm_image.caravan.id
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.worker_plane.id]
}
tags = var.tags
}