如何防止资源在 Azure DevOps Terraform 计划步骤期间被破坏?

How do I prevent resources from being destroyed during the Azure DevOps Terraform Plan Step?

我继承了一些职责,我的意思是在 AzureDevOps 发布管道部署中管理 Terraform。

我正在通过以下步骤使用 Terraform 任务: 在里面 证实 计划 申请

但是在计划输出期间我可以看到一些我不想删除的资源被破坏了。

azurerm_key_vault_secret.kv_secret_az_backup_storage_account_name will be destroyed

我一直在寻找一种方法来在创建 tfstate 文件期间禁用任何资源破坏,但在 Azure DevOps 中似乎没有这种方法。所以我最好的选择是我想求助于修改基础 main.tf 脚本,但我不知道如何。

这是要删除的资源之一。我已改名以保持匿名。任何人都可以建议解决我的困境吗?

resource "azurerm_key_vault_secret" "kv_secret_az_storage_account_name" {
  name         = "storage-account-name"
  value        = azurerm_storage_account.storage_account.name
  key_vault_id = azurerm_key_vault.keyvault.id
  depends_on   = [azurerm_storage_account.storage_account]
}

plan 阶段不会破坏您的资源,也不会创建新资源。它确实会告诉您 运行 apply.

时会发生什么

所以

azurerm_key_vault_secret.kv_secret_az_backup_storage_account_name will be destroyed

这只是说,如果您 运行 申请,您的存储帐户将被销毁。

但由于它试图删除,这意味着 terrafrom 会保留有关此资源的状态信息。所以它被创建为 terraform 现在如果你想把它放在范围之外 - 我的意思是你不想让你的 teffafrom 脚本维护它更长的时间你可以使用 state rm command.

Items removed from the Terraform state are not physically destroyed. Items removed from the Terraform state are only no longer managed by Terraform. For example, if you remove an AWS instance from the state, the AWS instance will continue running, but terraform plan will no longer see that instance.