forked from crayon/terraform-azurerm-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_disk.tf
32 lines (28 loc) · 1.75 KB
/
data_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
resource "azurerm_managed_disk" "data_disk" {
for_each = { for d in var.data_disks : d.name => d }
name = each.value.name
location = var.location
resource_group_name = var.resource_group
storage_account_type = each.value.storage_account_type
create_option = title(each.value.create_option)
disk_size_gb = each.value.disk_size_gb
zone = var.availability_zone
disk_encryption_set_id = each.value.disk_encryption_set_id
# Disk Access Settings
disk_access_id = each.value.disk_access_id
public_network_access_enabled = each.value.disk_access_id != null ? false : each.value.public_network_access_enabled
network_access_policy = each.value.disk_access_id != null ? "AllowPrivate" : each.value.network_access_policy
# If create_option is anything other than Empty,
# we need to define the supporting attribute.
source_resource_id = contains(["copy", "restore"], lower(each.value.create_option)) ? each.value.additional_settings.source_resource_id : null
source_uri = lower(each.value.create_option) == "import" ? each.value.additional_settings.source_uri : null
image_reference_id = lower(each.value.create_option) == "fromimage" ? each.value.additional_settings.image_reference_id : null
tags = var.tags
}
resource "azurerm_virtual_machine_data_disk_attachment" "data_disk" {
for_each = { for d in var.data_disks : d.name => d }
managed_disk_id = azurerm_managed_disk.data_disk[tostring(each.value.name)].id
virtual_machine_id = local.os_type == "windows" ? azurerm_windows_virtual_machine.machine[0].id : azurerm_linux_virtual_machine.machine[0].id
lun = each.value.lun
caching = each.value.caching
}