Azure Compute Virtual Machine Data Disk Attachment
This page shows how to write Terraform for Compute Virtual Machine Data Disk Attachment and write them securely.
azurerm_virtual_machine_data_disk_attachment (Terraform)
The Virtual Machine Data Disk Attachment in Compute can be configured in Terraform with the resource name azurerm_virtual_machine_data_disk_attachment
. The following sections describe 9 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_virtual_machine_data_disk_attachment" "disk0" {
managed_disk_id = azurerm_managed_disk.disk0.id
virtual_machine_id = var.vmID
lun = "0"
caching = var.caching
}
resource "azurerm_virtual_machine_data_disk_attachment" "disk0" {
managed_disk_id = azurerm_managed_disk.disk0.id
virtual_machine_id = var.vmID
lun = "0"
caching = var.caching
}
resource "azurerm_virtual_machine_data_disk_attachment" "diskattachment_vhgrrpoddb01" {
count = 4
managed_disk_id = element(azurerm_managed_disk.managedisk_vhgrrpoddb01.*.id, count.index)
virtual_machine_id = element(azurerm_virtual_machine.vm.*.id, element(var.disk_vm_vhgrrpoddb01, count.index))
lun = element(var.disk_attachment_lun1,count.index)
caching = element(var.disk_attachment_caching1,count.index)
resource "azurerm_virtual_machine_data_disk_attachment" "diskbw4hana-1" {
managed_disk_id = azurerm_managed_disk.diskbw4hana-1.id
virtual_machine_id = azurerm_virtual_machine.bw4hanavm.id
caching = "ReadWrite"
lun = 10
}
resource "azurerm_virtual_machine_data_disk_attachment" "diskmdcposolman-1" {
managed_disk_id = azurerm_managed_disk.diskmdcposolman-1.id
virtual_machine_id = azurerm_virtual_machine.mdcposolmanvm.id
caching = "ReadWrite"
lun = 10
}
resource "azurerm_virtual_machine_data_disk_attachment" "sql_data" {
virtual_machine_id = azurerm_windows_virtual_machine.vm01.id
managed_disk_id = azurerm_managed_disk.sql_data.id
lun = 0
caching = "None"
}
resource "azurerm_virtual_machine_data_disk_attachment" "gamedisk_ultradisk_attachment" {
managed_disk_id = azurerm_managed_disk.gamedisk_ultradisk.id
virtual_machine_id = data.azurerm_virtual_machine.vm.id
lun = "10"
caching = "None"
}
resource "azurerm_virtual_machine_data_disk_attachment" "premium1" {
managed_disk_id = azurerm_managed_disk.premium1.id
virtual_machine_id = azurerm_linux_virtual_machine.test.id
lun = "1"
caching = "ReadOnly"
}
resource "azurerm_virtual_machine_data_disk_attachment" "web_vms_disk1_attach" {
managed_disk_id = azurerm_managed_disk.web_vms_disk1.id
virtual_machine_id = element(module.web_vms.vm_ids, 0)
lun = "0"
caching = "None"
}
Parameters
-
caching
required - string -
create_option
optional - string -
id
optional computed - string -
lun
required - number -
managed_disk_id
required - string -
virtual_machine_id
required - string -
write_accelerator_enabled
optional - bool -
timeouts
single block
Explanation in Terraform Registry
Manages attaching a Disk to a Virtual Machine.
NOTE: Data Disks can be attached either directly on the
azurerm_virtual_machine
resource, or using theazurerm_virtual_machine_data_disk_attachment
resource - but the two cannot be used together. If both are used against the same Virtual Machine, spurious changes will occur. -> Please Note: only Managed Disks are supported via this separate resource, Unmanaged Disks can be attached using thestorage_data_disk
block in theazurerm_virtual_machine
resource.
Tips: Best Practices for The Other Azure Compute Resources
In addition to the azurerm_linux_virtual_machine, Azure Compute has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_linux_virtual_machine
Ensure to use SSH authentication for virtual machines
It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.
azurerm_managed_disk
Ensure to enable the encryption on managed disks
It is better to enable the encryption on managed disks.
azurerm_virtual_machine
Ensure to use SSH authentication for virtual machines
It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.
Azure Resource Manager Example
Azure Resource Manager code does not have the related resource.
Frequently asked questions
What is Azure Compute Virtual Machine Data Disk Attachment?
Azure Compute Virtual Machine Data Disk Attachment is a resource for Compute of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Compute Virtual Machine Data Disk Attachment?
For Terraform, the lasertown/throughput_test, lasertown/sles_upgrade_sp_swap and Lexar7/SAP_Deployment source code examples are useful. See the Terraform Example section for further details.