Error Importing existing resources into Terraform State File

白昼怎懂夜的黑 提交于 2019-12-12 23:59:54

问题


I am attempting to refactor some of my modules, which requires me to move existing resources into a different state file.

Normally importing resources is monotonous but straightforward.

I do not know how to interpret the following "The number of path segments is not divisible by 2" error when attempting to import any of these resources.

This is happening on all resources I am attempting to import (which I have successfully done many times in the past)

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 Version:

CLI> terraform -v
Terraform v0.11.11
+ provider.azurerm v1.20.0

回答1:


your resource ID is wrong (/resource/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01). it should be this:

/subscriptions/XXX/resourceGroups/XXX/providers/Microsoft.Compute/virtualMachines/stguemm01


来源:https://stackoverflow.com/questions/53950204/error-importing-existing-resources-into-terraform-state-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!