-
Notifications
You must be signed in to change notification settings - Fork 0
/
r-disk.tf
36 lines (31 loc) · 1.04 KB
/
r-disk.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
locals {
data_disks = [
for _index, element in var.data_disks :
merge(
element, {
name = coalesce(
element.name,
format("disk-%s-%02.0f", trimprefix(var.name, "vm-"), sum([_index, 1]))
)
}
)
]
}
resource "azurerm_managed_disk" "this" {
for_each = { for element in local.data_disks : element.name => element }
name = each.value.name
location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
storage_account_type = each.value.storage_account_type
create_option = each.value.create_option
disk_size_gb = each.value.disk_size_gb
zone = var.zone
}
resource "azurerm_virtual_machine_data_disk_attachment" "this" {
for_each = { for element in local.data_disks : element.name => element }
managed_disk_id = azurerm_managed_disk.this[each.key].id
virtual_machine_id = local.virtual_machine.id
lun = each.value.lun
caching = each.value.caching
}