简体   繁体   English

使用 Terraform 导入 Azure Windows 虚拟机时出错

[英]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.

相关问题 来自 Azure 市场映像的虚拟机,其中 terraform 脚本出现错误 - Virtual Machine from Azure marketplace image with terraform script having an error Terraform - 从快照启动 Azure 虚拟机 - Terraform - launching an Azure virtual machine from a snapshot Azure 虚拟机扩展文件Uris 路径与Terraform - Azure Virtual Machine Extension fileUris path with Terraform Terraform - Azure - 同时使用“azurerm_windows_virtual_machine”和“azurerm_mssql_virtual_machine” - 但未配置 SQL 存储 - Terraform - Azure - Using "azurerm_windows_virtual_machine" and "azurerm_mssql_virtual_machine" together - but SQL Storage isn't getting configured Windows Azure虚拟机性能 - Windows Azure Virtual machine performance Azure虚拟机/ Windows Server 2012和“此网页不可用”错误 - Azure Virtual Machine / Windows Server 2012 and “This web page is not available” error Terraform 中的虚拟机扩展,由于版本错误 - Virtual Machine Extension in Terraform, error due to Version Azure-Windows Azure虚拟机问题 - Azure - Windows Azure Virtual Machine Issue 使用Terraform的Azure虚拟机扩展文件URL位置 - Azure Virtual Machine Extension file URL location with Terraform 如何在 Terraform 中为 Azure 负载均衡器添加具有虚拟机 IP 的后端 - How to add a backend with virtual machine IP for Azure Load Balancer in Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM