I'm trying to import 2 existing azure resources (1 .net 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-.net /subscriptions/11111111/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/my-.net-01
Everything works perfectly, the terraform.tfstate
file gets updated with the .net 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 .net
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.
I was just going to delete the question as it is such a simple problem/solution, but because the error is so non-descript as to the cause this might be helpful to someone
Apparently Is terraform for you have a typo in your resource name.
resource "azurem_resource_group"
should be (in this case) resource "azurerm_resource_group"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.