Problem
When performing an import locally on a Windows machine using GitBash, a user may encounter an error similar to the following:
$ terraform import azurerm_resource_group.test "/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group"
azurerm_resource_group.test: Importing from ID "C:/Program Files/Git/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group"...
╷
│ Error: ID contained more segments than required: "C:/Program Files/Git/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group", map[Program Files:Git]
Cause
This issue is caused because Azure resource IDs start with a Slash which will cause a POSIX-to-Windows conversion to take place malforming the resource ID.
Solution
In order to avoid the conversion, a user can run the following command before doing the import:
export MSYS_NO_PATHCONV=1
After setting this environment variable, the import should succeed:
$ export MSYS_NO_PATHCONV=1
$ terraform import azurerm_resource_group.test "/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group"
azurerm_resource_group.test: Importing from ID "/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group"...
azurerm_resource_group.test: Import prepared!
Prepared azurerm_resource_group for import
azurerm_resource_group.test: Refreshing state... [id=/subscriptions/<REDACTED>/resourceGroups/my-test-resource-group]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
Additional Information
References
Azure CLI Documentation On Auto-Translation Of Resource IDs