[英]Error importing Azure Windows Virtual Machine with Terraform
I'm using the terraform azurerm provider 2.0.0 and I'm trying to learn how everything works.我正在使用 terraform azurerm provider 2.0.0,我正在尝试了解一切是如何工作的。 I have a bunch of existing azure resources including a bunch of Windows VMs in a Resource Group.我有一堆现有的 azure 资源,包括资源组中的一堆 Windows VM。 It appears that I have to manually import each of them one at a time using the看来我必须使用
terraform import azurerm_wndows_virtual_machine.<myvmname> /subscriptions/<mysub>/resourceGroups/<myrg>/providers/Microsoft.Compute/virtualMachines/<myvmname>
command.命令。
However, when I try to do this I get但是,当我尝试这样做时,我得到
Error: The "azurerm_windows_virtual_machine" resource doesn't support attaching OS Disks - please use the `azurerm_virtual_machine` resource instead
My understanding is that I need to put the imported resource in the terraform file as an empty element in order for terraform to connect the imported item with an item in the file.我的理解是,我需要将导入的资源作为一个空元素放在 terraform 文件中,以便 terraform 将导入的项目与文件中的项目连接起来。
My terraform script looks like this我的 terraform 脚本看起来像这样
# Configure the Azure provider
provider "azurerm" {
version = "=2.0.0"
subscription_id = "00000000-0000-0000-0000-000000000000"
tenant_id = "00000000-0000-0000-0000-000000000000"
}
resource "azurerm_resource_group" "myrg" {
}
resource "azurerm_windows_virtual_machine" "myvmname" {
}
What am I doing wrong?我究竟做错了什么?
From this azurerm_windows_virtual_machine terraform document,从此azurerm_windows_virtual_machine terraform 文档中,
Note This resource does not support Unmanaged Disks.注意 此资源不支持非托管磁盘。 If you need to use Unmanaged Disks you can continue to use the azurerm_virtual_machine resource instead.如果需要使用非托管磁盘,可以继续使用 azurerm_virtual_machine 资源。
Note This resource does not support attaching existing OS Disks.注意 此资源不支持附加现有 OS 磁盘。 You can instead capture an image of the OS Disk or continue to use the azurerm_virtual_machine resource instead.您可以改为捕获 OS 磁盘的映像或继续使用 azurerm_virtual_machine 资源。
It seems that you are trying to import a Azure VM that have Unmanaged Disks or attached existing OS Disks.您似乎正在尝试导入具有非托管磁盘或附加现有操作系统磁盘的 Azure VM。 In this case, you need to use azurerm_virtual_machine resource instead.在这种情况下,您需要改用azurerm_virtual_machine资源。
Your terraform will like this,你的 terraform 会喜欢这个,
# Configure the Azure provider
provider "azurerm" {
version = "=2.0.0"
subscription_id = "00000000-0000-0000-0000-000000000000"
tenant_id = "00000000-0000-0000-0000-000000000000"
}
resource "azurerm_resource_group" "myrg" {
}
resource "azurerm_virtual_machine" "myvmname" {
}
Virtual Machines can be imported using the resource id, eg可以使用资源 ID 导入虚拟机,例如
terraform import azurerm_virtual_machine.myvmname /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.compute/virtualMachines/machine1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.