azure - 使用 Github CICD 运行 Azure DevOps 管道时,具有 ID 的 Terraform 资源已存在错误

标签 azure azure-devops terraform terraform-provider-azure infrastructure-as-code

我正在按照此视频的教程进行操作:https://www.youtube.com/watch?v=Ff0DoAmpv6w&t=5905s (Azure DevOps:使用 Terraform 配置 API 基础设施)T

这是他的 github 代码,和我的非常相似:https://github.com/binarythistle/S03E03---Azure-Devops-and-Terraform

问题是当 Azure 上不存在资源组时,假设我手动删除了它,运行管道会创建它以及我的容器实例。但是当我尝试提交一些代码更改并推送到 github 时再次执行 pipline 时,它​​会显示

azurerm_resource_group.rg: Creating...
╷
│ Error: A resource with the ID "/subscriptions/xxxxx/resourceGroups/xxx" already exists
│ 
│   with azurerm_resource_group.rg,
│   on main.tf line 30, in resource "azurerm_resource_group" "rg":
│   30: resource "azurerm_resource_group" "rg" {

它难道不应该记住之前已经创建过资源并跳过此步骤 - 或执行其他操作吗?

我的观察

看起来第一次运行时,日志显示执行了一些额外的步骤

azurerm_resource_group.rg: Refreshing state... [id=/subscriptions/xxxxx/resourceGroups/xxx]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:

  # azurerm_resource_group.rg has been deleted
  - resource "azurerm_resource_group" "rg" {
        id       = "/subscriptions/xxxxx/resourceGroups/xxx"
      - location = "australiaeast" -> null
      - name     = "myTFResourceGroup" -> null
    }
Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

第二次运行管道时,日志显示:

Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.

但是随后显示了上述错误。

最佳答案

删除 .terraform 本地文件夹以清理缓存,然后再次运行 terraform init 并重试运行管道。

关于azure - 使用 Github CICD 运行 Azure DevOps 管道时,具有 ID 的 Terraform 资源已存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73751660/

相关文章:

Azure Front Door 后端详细介绍了现有 Front Door 问题的补充

terraform - 如何修复provider.vault : no vault token found?

azure - az synapse Spark 作业提交

git - 防止分支在 PR 完成时被删除

sql - Azure 开发运营 : Continuous deployment for sql script

azure - 在 terraform 中引用对象/ map 类型值中的值的正确方法是什么

terraform - 使用 Terraform 制作 Azure 逻辑应用程序,有哪些限制?

c# - 如何捕获 Windows Azure(辅助)角色中未处理的异常

azure - 如何使用 Azure 数据工厂 GUI 将多个 blob 文件压缩到一个 .gzip 中?

java - 从 Azure Blob 存储下载大文件时避免 OutOfMemoryError