![](/img/trans.png)
[英]Getting Terraform resource already exists error with resource just created by Terraform
[英]Lock file error when importing resource in terraform
我正在嘗試導入 2 個現有的 azure 資源(1 個 .net 和 1 個資源組)。
如果我將以下內容添加到我的 main.tf
resource "azurerm_virtual_network" "my-vnet" {
}
並運行terraform import azurerm_virtual.network.my-.net /subscriptions/11111111/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/my-.net-01
一切正常, terraform.tfstate
文件更新了 .net 信息等。
如果我然后將以下內容添加到 main.tf
resource "azurem_resource_group" "my-net-rsg" {
}
並運行terraform import azurem_resource_group.my.net-rsg /subscriptions/11111111/resourceGroups/my.net-rsg
如果我然后刪除
resource "azurem_resource_group" "my-net-rsg" {
}
並運行相同的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)
}
即使我真的將 output 復制並粘貼回我的main.tf
文件,我也會從上面的屏幕截圖中得到同樣的錯誤。
我試過只配置資源組
我試過在 .net 之前先進行資源配置
我在不同的目錄中嘗試了一個新的terraform init
並再次完成了整個過程。
每次如果我在main.tf
中有資源組,它都會抱怨鎖定文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.