我正在尝试重构某些模块,这需要我将现有资源移至其他状态文件中。
通常,导入资源是单调但简单的。
我不知道如何解释以下 “尝试导入任何这些资源时,路径段的数量不能被2整除” 的错误。
>这种情况正在我尝试导入的所有资源上发生(过去我已经成功完成了很多次)
CLI> terraform import azurerm_virtual_machine.east_mm01_vm /resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01
Acquiring state lock. This may take a few moments...
azurerm_virtual_machine.east_mm01_vm: Importing from ID "/resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01"...
azurerm_virtual_machine.east_mm01_vm: Import complete!
Imported azurerm_virtual_machine (ID: /resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01)
azurerm_virtual_machine.east_mm01_vm: Refreshing state... (ID: /resource/subscriptions/XXX...soft.Compute/virtualMachines/stguemm01)
Error: azurerm_virtual_machine.east_mm01_vm (import id: /resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01): 1 error(s) occurred:
* import azurerm_virtual_machine.east_mm01_vm result: /resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01: azurerm_virtual_machine.east_mm01_vm: The number of path segments is not divisible by 2 in "resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01"
Terraform版本:
CLI> terraform -v
Terraform v0.11.11
+ provider.azurerm v1.20.0
答案 0 :(得分:0)
您的资源ID错误(/resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01
)。应该是这样:
/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01