在我的Azure APIM中,我试图将API操作添加到我的API中,以便我可以通过Terraform向其添加策略。除了azurerm_api_management_api_operation
部分,其他都工作正常。它基本上是用众所周知的Terraform错误A resource with ID ... already exists..
出错。
我的Terraform的一个片段是:
resource "azurerm_api_management_api" "business_api_v1" {
name = "business-api-v1"
resource_group_name = data.azurerm_resource_group.app_rg.name
api_management_name = module.api.name
revision = "1"
display_name = "Business API v1"
path = "business-data/v1"
protocols = ["https"]
version = "v1"
version_set_id = azurerm_api_management_api_version_set.business-api-version-set.id
import {
content_format = "openapi+json"
content_value = <<JSON
<...content of json open API spec...>
JSON
}
}
resource "azurerm_api_management_api_operation" "search_businesses_v1" {
operation_id = "tf-search-businesses"
api_name = azurerm_api_management_api.business_api_v1.name
api_management_name = module.api.name
resource_group_name = data.azurerm_resource_group.app_rg.name
display_name = "Search Businesses"
method = "GET"
url_template = "/businesses"
description = "Search Businesses by name"
}
我不知道为什么Terraform创建它,然后给出错误:
A resource with the ID "/subscriptions/<sub_id>/resourceGroups/<resource_group>/providers/Microsoft.ApiManagement/service/abcd/apis/business-api-v1/operations/tf-search-businesses" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_api_management_api_operation" for more information.
我删除了我的API (&(所讨论的底层资源)多次运行plan
和apply
阶段。在apply
阶段,它在创建资源后抛出错误。100%确定没有其他人创建它,我已经尝试重命名name
属性几次,因为我试图解决这个问题。
有谁知道是什么问题吗?谢谢。
- 当资源被部署到时创建地形状态文件当资源被创建时,azure和它的状态改变。
- 所以正如你所说,你已经通过UI删除了api操作,即;的门户,起程拓殖状态可能不是与真实的国家。
由于它们将被置于地形管理控制之下,因此请务必尝试地形导入以匹配@markus所说的现有更改,并与管理层的访问权限进行检查。
terraform import <terraform_id> <azure_resource_id>
或
- 尝试删除Terraform的本地缓存和所有资源,并再次应用更改。
- As terraform将状态保存为本地terraform。状态,试着
- 如果您试图更改资源引用的名称你的地形状态文件。
可以使用terraform state mv
- 如果您想要删除稍后创建的资源,但希望保留你可以使用
terraform state rm {name of resource}
相似的问题:
- terraform-provider-azurerm/issues.github 在Azure DevOps中应用
- 平台失败,资源的ID为"已经exists"-开发社区