-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstorage.tf
376 lines (302 loc) · 16.3 KB
/
storage.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
resource "oci_core_volume" "fs1_blockvolume" {
count = (var.fs_ha ? (local.derived_storage_server_node_count/2)*local.derived_fs1_disk_count : local.derived_fs1_disk_count * local.derived_storage_server_node_count)
availability_domain = local.ad
compartment_id = var.compartment_ocid
display_name = "${local.cluster_name}_xfs1-target${count.index % local.derived_fs1_disk_count + 1}"
size_in_gbs = var.fs1_disk_size
vpus_per_gb = var.volume_type_vpus_per_gb_mapping[(var.fs1_disk_perf_tier)]
}
resource "oci_core_volume_attachment" "fs1_blockvolume_attach" {
attachment_type = "iscsi"
count = (local.derived_storage_server_node_count * local.derived_fs1_disk_count)
instance_id = element(oci_core_instance.storage_server.*.id, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs1_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count),)
volume_id = element(oci_core_volume.fs1_blockvolume.*.id, (var.fs_ha ? floor(count.index/2) : count.index))
is_shareable = var.fs_ha ? true : false
# A "+ 1" was added to "floor(count.index/2) + 1" to start from /dev/oracleoci/oraclevdc instead of /dev/oracleoci/oraclevdb, since we need the /dev/oracleoci/oraclevdb for stonith_fencing device.
##device = var.volume_attach_device_mapping[((var.fs_ha ? floor(count.index/2) + 1 : count.index % local.derived_fs1_disk_count))]
# If uhp is used and HA, then /dev/oracleoci/oraclevdc is reserved for uhp. Non-uhp starts from /dev/oracleoci/oraclevdd
# with uhp logic
device = var.use_uhp ? ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 2 : (count.index % local.derived_fs1_disk_count) + 1 )] ) : ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 1 : count.index % local.derived_fs1_disk_count)] )
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs1_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count)
)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion[0].public_ip
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"sudo -s bash -c 'set -x && iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}'",
"sudo -s bash -c 'set -x && iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic '",
"sudo -s bash -c 'set -x && iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l '",
]
}
}
resource "null_resource" "notify_storage_server_nodes_fs1_block_attach_complete" {
depends_on = [ oci_core_volume_attachment.fs1_blockvolume_attach ]
count = local.derived_storage_server_node_count
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion.*.public_ip[0]
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"set -x",
"sudo touch /tmp/block-attach.complete",
]
}
}
resource "oci_core_volume" "fs2_blockvolume" {
count = (var.fs_ha ? (local.derived_storage_server_node_count/2)*local.derived_fs2_disk_count : local.derived_fs2_disk_count * local.derived_storage_server_node_count)
availability_domain = local.ad
compartment_id = var.compartment_ocid
display_name = "${local.cluster_name}_xfs2-target${count.index % local.derived_fs2_disk_count + 1}"
size_in_gbs = var.fs2_disk_size
vpus_per_gb = var.volume_type_vpus_per_gb_mapping[(var.fs2_disk_perf_tier)]
}
resource "oci_core_volume_attachment" "fs2_blockvolume_attach" {
attachment_type = "iscsi"
count = (local.derived_storage_server_node_count * local.derived_fs2_disk_count)
instance_id = element(oci_core_instance.storage_server.*.id, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs2_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count),)
volume_id = element(oci_core_volume.fs2_blockvolume.*.id, (var.fs_ha ? floor(count.index/2) : count.index))
is_shareable = var.fs_ha ? true : false
# A "+ 1" was added to "floor(count.index/2) + 1" to start from /dev/oracleoci/oraclevdc instead of /dev/oracleoci/oraclevdb, since we need the /dev/oracleoci/oraclevdb for stonith_fencing device.
##device = var.volume_attach_device_mapping[((var.fs_ha ? floor(count.index/2) + 1 : count.index % local.derived_fs2_disk_count))]
# If uhp is used and HA, then /dev/oracleoci/oraclevdc is reserved for uhp. Non-uhp starts from /dev/oracleoci/oraclevdd
# with uhp logic
device = var.use_uhp ? ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 2 + local.derived_fs1_disk_count: (count.index % local.derived_fs2_disk_count) + 1 + local.derived_fs1_disk_count)] ) : ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 1 + local.derived_fs1_disk_count : (count.index % local.derived_fs2_disk_count) + local.derived_fs1_disk_count )] )
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs2_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count)
)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion[0].public_ip
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"sudo -s bash -c 'set -x && iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}'",
"sudo -s bash -c 'set -x && iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic '",
"sudo -s bash -c 'set -x && iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l '",
]
}
}
resource "null_resource" "notify_storage_server_nodes_fs2_block_attach_complete" {
depends_on = [ oci_core_volume_attachment.fs2_blockvolume_attach ]
count = local.derived_storage_server_node_count
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion.*.public_ip[0]
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"set -x",
"sudo touch /tmp/block-attach.complete",
]
}
}
resource "oci_core_volume" "fs3_blockvolume" {
count = (var.fs_ha ? (local.derived_storage_server_node_count/2)*local.derived_fs3_disk_count : local.derived_fs3_disk_count * local.derived_storage_server_node_count)
availability_domain = local.ad
compartment_id = var.compartment_ocid
display_name = "${local.cluster_name}_xfs3-target${count.index % local.derived_fs3_disk_count + 1}"
size_in_gbs = var.fs3_disk_size
vpus_per_gb = var.volume_type_vpus_per_gb_mapping[(var.fs3_disk_perf_tier)]
}
resource "oci_core_volume_attachment" "fs3_blockvolume_attach" {
attachment_type = "iscsi"
count = (local.derived_storage_server_node_count * local.derived_fs3_disk_count)
instance_id = element(oci_core_instance.storage_server.*.id, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs3_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count),)
volume_id = element(oci_core_volume.fs3_blockvolume.*.id, (var.fs_ha ? floor(count.index/2) : count.index))
is_shareable = var.fs_ha ? true : false
# A "+ 1" was added to "floor(count.index/2) + 1" to start from /dev/oracleoci/oraclevdc instead of /dev/oracleoci/oraclevdb, since we need the /dev/oracleoci/oraclevdb for stonith_fencing device.
##device = var.volume_attach_device_mapping[((var.fs_ha ? floor(count.index/2) + 1 : count.index % local.derived_fs3_disk_count))]
# If uhp is used and HA, then /dev/oracleoci/oraclevdc is reserved for uhp. Non-uhp starts from /dev/oracleoci/oraclevdd
# with uhp logic
device = var.use_uhp ? ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 2 + local.derived_fs1_disk_count + local.derived_fs2_disk_count: (count.index % local.derived_fs3_disk_count) + 1 + local.derived_fs1_disk_count + local.derived_fs2_disk_count )] ) : ( var.volume_attach_device_mapping[(var.fs_ha ? floor(count.index/2) + 1 + local.derived_fs1_disk_count + local.derived_fs2_disk_count: (count.index % local.derived_fs3_disk_count) + local.derived_fs1_disk_count + local.derived_fs2_disk_count )] )
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, (var.fs_ha ? ((count.index % 2) + (floor(count.index/(local.derived_fs3_disk_count*2))*2)) : count.index % local.derived_storage_server_node_count)
)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion[0].public_ip
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"sudo -s bash -c 'set -x && iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}'",
"sudo -s bash -c 'set -x && iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic '",
"sudo -s bash -c 'set -x && iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l '",
]
}
}
resource "null_resource" "notify_storage_server_nodes_fs3_block_attach_complete" {
depends_on = [ oci_core_volume_attachment.fs3_blockvolume_attach ]
count = local.derived_storage_server_node_count
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion.*.public_ip[0]
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"set -x",
"sudo touch /tmp/block-attach.complete",
]
}
}
resource "oci_core_volume" "stonith_fencing_blockvolume" {
count = (var.fs_ha ? 1 : 0)
availability_domain = local.ad
compartment_id = var.compartment_ocid
display_name = "${local.cluster_name}_nfs-stonith-fencing-sbd"
size_in_gbs = "50"
# Lower cost Block volume
vpus_per_gb = "10"
}
resource "oci_core_volume_attachment" "stonith_fencing_blockvolume_attach" {
attachment_type = "iscsi"
count = (var.fs_ha ? 2 : 0)
instance_id = element(oci_core_instance.storage_server.*.id, count.index, )
volume_id = element(oci_core_volume.stonith_fencing_blockvolume.*.id, 0)
is_shareable = var.fs_ha ? true : false
device = var.volume_attach_device_mapping[0]
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index )
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion[0].public_ip
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"sudo -s bash -c 'set -x && iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}'",
"sudo -s bash -c 'set -x && iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic '",
"sudo -s bash -c 'set -x && iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l '",
]
}
}
resource "null_resource" "notify_storage_server_nodes_stonith_fencing_block_attach_complete" {
depends_on = [ oci_core_volume_attachment.stonith_fencing_blockvolume_attach ]
count = (var.fs_ha ? 2 : 0)
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion.*.public_ip[0]
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"set -x",
"sudo touch /tmp/stonith_fencing_block-attach.complete",
]
}
}
resource "oci_core_volume" "uhp_blockvolume" {
count = var.use_uhp ? 1 : 0
availability_domain = local.ad
compartment_id = var.compartment_ocid
display_name = "${local.cluster_name}_xfs-uhp-target1"
# UHP Block volume
size_in_gbs = var.uhp_fs0_disk_size
vpus_per_gb = var.volume_type_vpus_per_gb_mapping[(var.uhp_fs0_disk_perf_tier)]
}
resource "oci_core_volume_attachment" "uhp_blockvolume_attach" {
attachment_type = "iscsi"
count = var.use_uhp ? (var.fs_ha ? 2 : 1) : 0
instance_id = element(oci_core_instance.storage_server.*.id, count.index, )
volume_id = element(oci_core_volume.uhp_blockvolume.*.id, 0)
is_shareable = var.fs_ha ? true : false
device = var.fs_ha ? var.volume_attach_device_mapping[1] : var.volume_attach_device_mapping[0]
/*
NOTE: FOR UHP, Block Plugin does login for iSCSI. The below remote-exec is not required.
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index )
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion[0].public_ip
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"/usr/bin/hostname",
"sudo -s bash -c 'set -x && iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}'",
"sudo -s bash -c 'set -x && iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic '",
"sudo -s bash -c 'set -x && iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l '",
]
}
*/
}
/*
NOTE: FOR UHP, Block Plugin does login for iSCSI.
Hence the below is not required and to confirm attach complete, do a check before using the volume (see _nfs_install_storage.sh.j2)
*/
/*
resource "null_resource" "notify_storage_server_nodes_uhp_block_attach_complete" {
depends_on = [ oci_core_volume_attachment.uhp_blockvolume_attach ]
count = var.use_uhp ? (var.fs_ha ? 2 : 1) : 0
provisioner "remote-exec" {
connection {
agent = false
timeout = "30m"
host = element(oci_core_instance.storage_server.*.private_ip, count.index)
user = var.ssh_user
private_key = tls_private_key.ssh.private_key_pem
bastion_host = oci_core_instance.bastion.*.public_ip[0]
bastion_port = "22"
bastion_user = var.ssh_user
bastion_private_key = tls_private_key.ssh.private_key_pem
}
inline = [
"set -x",
"sudo touch /tmp/uhp_block-attach.complete",
]
}
}
*/