[英]Lock file error when importing resource in terraform
I'm trying to import 2 existing azure resources (1 .net and 1 resource group).我正在尝试导入 2 个现有的 azure 资源(1 个 .net 和 1 个资源组)。
If I add the following to my main.tf如果我将以下内容添加到我的 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
并运行
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.一切正常,
terraform.tfstate
文件更新了 .net 信息等。
If I then add the following to the main.tf如果我然后将以下内容添加到 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
并运行
terraform import azurem_resource_group.my.net-rsg /subscriptions/11111111/resourceGroups/my.net-rsg
I get the following error我收到以下错误
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并运行相同的
terraform import azurem_resource_group.my.net-rsg /subscriptions/11111111/resourceGroups/my.net-rsg
我得到一个错误(非常正确和预期)说
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.即使我真的将 output 复制并粘贴回我的
main.tf
文件,我也会从上面的屏幕截图中得到同样的错误。
I've tried only having the resource group config我试过只配置资源组
I've tried having the resource config first before the .net我试过在 .net 之前先进行资源配置
I've tried a fresh terraform init
in a different directory and walking through the process again.我在不同的目录中尝试了一个新的
terraform init
并再次完成了整个过程。
Every time if I have the resource group in the main.tf
it complains about the lock file.每次如果我在
main.tf
中有资源组,它都会抱怨锁定文件。
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.
是 terraform 因为您的资源名称中有错字。
resource "azurem_resource_group"
should be (in this case) resource "azurerm_resource_group"
resource "azurem_resource_group"
应该是(在这种情况下) resource "azurerm_resource_group"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.