問題描述
Terraform 狀態 rm 命令 (Terraform state rm command)
我創建了一個 azure terraform 模板來創建資源組和 vnet。我已經運行了 terraform plan 然後申請。創造了環境。現在,出於測試目的,有人通過 Azure 門戶在同一資源組中創建了一個存儲帳戶。從那以後,每當我運行 terraform plan 時,它都會顯示要銷毀的資源組狀態。
因此我在模板中重命名了資源組,並運行了 terraform plan。它顯示了新資源組的創建以及現有資源組的刪除。
我知道正在發生這種情況,因為 terraform 狀態文件包含現有資源組的信息。我正在嘗試通過以下命令從狀態文件中刪除現有資源組
terraform state rm azurem_resource_group.rg <
參考解法
方法 1:
To remove the reference of the existing resource group in the state file, you could run it without providing the specific resource id.
terraform state rm azurerm_resource_group.rg
You also could show the state with terraform state list
.
(by Asterix、Nancy Xiong)