我正在按照此视频的教程进行操作: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/