简体   繁体   English

terraform导入资源时锁文件错误

[英]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.

相关问题 获取 Terraform 资源已存在错误,资源刚刚由 Terraform 创建 - Getting Terraform resource already exists error with resource just created by Terraform 即使资源存在,将 gcp 资源导入 terraform 也会失败 - importing gcp resource into terraform fails even if the resource exists Terraform:获取 state 锁时出错:ConditionalCheckFailedException - Terraform: Error acquiring the state lock: ConditionalCheckFailedException Terraform Apply Error: Code="InvalidResourceName" Message="Resource name is invalid" 创建 VPN-GW 模块时 - Terraform Apply Error: Code="InvalidResourceName" Message="Resource name is invalid" When creating VPN-GW Module Azure terraform 导入错误,无法导入资源 - Azure terraform import error, unable to import resource `Error 403: Insufficient regional quota to satisfy request: resource "SSD_TOTAL_GB"` when creating kube.netes cluster with terraform - `Error 403: Insufficient regional quota to satisfy request: resource "SSD_TOTAL_GB"` when creating kubernetes cluster with terraform Terraform:googleapi:错误 403:资源项目权限被拒绝 - Terraform: googleapi: Error 403: Permission denied on resource project Terraform - 尽管已在同一文件中声明,但未找到变量的资源 - Terraform - Resource not found for variable despite having it declared in the same file Terraform 添加新用户时尝试替换现有资源 - Terraform trying to replace existing resource when new user is added Terraform 计划获取错误:无法从 state 解码资源 - Terraform plan getting Error: Failed to decode resource from state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM