'Lock file error when importing resource in terraform
I'm trying to import 2 existing azure resources (1 vnet and 1 resource group).
If I add the following to my main.tf
resource "azurerm_virtual_network" "my-vnet" {
}
and run terraform import azurerm_virtual_network.my-vnet /subscriptions/11111111/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/my-vnet-01
Everything works perfectly, the terraform.tfstate file gets updated with the vnet information etc.
If I then add the following to the main.tf
resource "azurem_resource_group" "my-net-rsg" {
}
and run terraform import azurem_resource_group.my-net-rsg /subscriptions/11111111/resourceGroups/my-net-rsg
If I then remove
resource "azurem_resource_group" "my-net-rsg" {
}
and run the same terraform import azurem_resource_group.my-net-rsg /subscriptions/11111111/resourceGroups/my-net-rsg I get an error (quite rightly & expectedly) saying
Before importing this resource, please create its configuration in the root module. For example:
resource "azurem_resource_group" "my-net-rsg" {
# (resource arguments)
}
Even if I literally copy and paste that output back into my main.tf file I get the same error from the screen shot above.
I've tried only having the resource group config
I've tried having the resource config first before the vnet
I've tried a fresh terraform init in a different directory and walking through the process again.
Every time if I have the resource group in the main.tf it complains about the lock file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

