I have an existing resource group on Azure with a VM running on it and have been playing around with Terraform to try and import the resource to my state file.
I ha
Using the Terraform Azure provider v1.16.0 I got a "Cannot parse Azure ID" error message:
terraform import azurerm_network_security_group.myterraformnsg "subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg"
azurerm_network_security_group.myterraformnsg: Importing from ID "subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg"...
azurerm_network_security_group.myterraformnsg: Import complete!
Imported azurerm_network_security_group (ID: subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg)
azurerm_network_security_group.myterraformnsg: Refreshing state... (ID: subscriptions/ef37d4b2-686a-494a-9001-5.../networkSecurityGroups/test-nsg)
Error: azurerm_network_security_group.myterraformnsg (import id: subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg): 1 error(s) occurred:
* import azurerm_network_security_group.myterraformnsg result: subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg: azurerm_network_security_group.myterraformnsg: Cannot parse Azure ID: parse subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg: invalid URI for request
Looking into the Azure provider source code I found out that you need to enter the full URL to the Azure resource - like this:
terraform import azurerm_network_security_group.myterraformnsg "https://portal.azure.com//resource/subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg"
azurerm_network_security_group.myterraformnsg: Importing from ID "https://portal.azure.com//resource/subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg"...
azurerm_network_security_group.myterraformnsg: Import complete!
Imported azurerm_network_security_group (ID: https://portal.azure.com//resource/subscriptions//resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/test-nsg)
azurerm_network_security_group.myterraformnsg: Refreshing state... (ID: https://portal.azure.com//networkSecurityGroups/test-nsg)
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.
Unfortunately, Import will only update the Terraform state.
It will not (yet) update the configuration file.
This makes the Import function less useful, IMO.