[英]Using Terraform, how do I create a VM on Azure that uses an existing managed disk?
I have imported a managed disk from a blob with terraform.我已经从带有 terraform 的 blob 中导入了托管磁盘。 Now I just need to create a VM with it (it's an OS disk).
现在我只需要用它创建一个虚拟机(它是一个操作系统磁盘)。 How?
如何?
I have:我有:
resource "azurerm_managed_disk" "MyDisk" {
name = "MyDisk"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
storage_account_type = "Standard_LRS"
create_option = "Import"
storage_account_id = azurerm_storage_account.temp_storage.id
source_uri = "${azurerm_storage_container.images.id}/MyDisk.vhd"
disk_size_gb = "32"
tags = {
environment = "staging"
}
}
azurerm_linux_virtual_machine doesn't seem to have any way to take this managed disk and make a VM with it. azurerm_linux_virtual_machine 似乎没有任何方法可以获取此托管磁盘并使用它创建 VM。 Anyone know how?
有谁知道怎么做?
thank you much非常感谢
You can use azurerm_virtual_machine_data_disk_attachment .您可以使用azurerm_virtual_machine_data_disk_attachment 。 Example:
例子:
resource "azurerm_virtual_machine_data_disk_attachment" "example" {
managed_disk_id = azurerm_managed_disk.MyDisk.id
virtual_machine_id = azurerm_virtual_machine.MyMachine.id
lun = "10"
caching = "ReadWrite"
}
# <https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine>
resource "azurerm_virtual_machine" "main" {
name = "VoIP-VM"
location = var.location
resource_group_name = azurerm_resource_group.VoIP.name
network_interface_ids = [azurerm_network_interface.VoIP.id]
vm_size = "Standard_F2"
# Uncomment this line to delete the OS disk automatically when deleting the VM
# delete_os_disk_on_termination = true
# Uncomment this line to delete the data disks automatically when deleting the VM
# delete_data_disks_on_termination = true
storage_os_disk {
name = "${azurerm_managed_disk.MyDisk.name}"
caching = "ReadWrite"
create_option = "Attach"
managed_disk_type = "Standard_LRS"
managed_disk_id = "${azurerm_managed_disk.MyDisk.id}"
os_type = "linux"
}
tags = {
environment = "staging"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.