使用已删除的名称创建 Azure API 管理会导致名称"already in use"错误



我之前使用Terraform创建并随后删除了Azure API管理服务。它在Azure门户中消失了。几小时后,当我尝试用相同的名称重新创建API管理时,我在Azure门户中得到了以下错误:"name already in use. Please select a different name."Terraform中也出现了类似的错误。

有人知道为什么即使我在资源组中看不到该名称,也不能重用该名称吗?

检查您的APIM服务是否已被软删除。如果资源已被软删除,并且您希望创建一个具有相同名称的新资源,则需要清除该资源,然后重新创建。

按名称获取软删除实例:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}?api-version=2020-06-01-preview

列出给定订阅的所有软删除实例:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/deletedservices?api-version=2020-06-01-preview

恢复已删除的APIM实例:

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.ApiManagement/service/{apimServiceName}?api-version=2020-06-01-preview

清除软删除的APIM实例:

DELETE https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}?api-version=2020-06-01-preview

我写了一篇文章,其中包含一些封装REST调用的PowerShell代码(函数(,因此您可以使用以下几个参数来调用该函数。

清除ApiManagementInstance-订阅Id$subId-位置$Location-名称$apimInstanceName

https://www.linkedin.com/pulse/purging-azure-api-management-instance-james-hughes/

正如其他人已经提到的,您的实例已被软删除。您需要terraform在销毁时清除实例,这是通过在提供程序部分添加一些配置选项来完成的https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/features-block#api_management

provider "azurerm" {
api_management {
# does not seem to work, insufficient rights?
purge_soft_delete_on_destroy         = true
# as of now next attribute exists only on docs, never worked for me
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/features-block#api_management
#recover_soft_deleted_api_management = false
}
----
}

根据地形文档,您的SP还需要具有recover权限。

您也可以使用az rest删除它

az rest --method delete --header "Accept=application/json" -u 'https://management.azure.com/subscriptions/123-123-123/providers/Microsoft.ApiManagement/locations/[eastus]/deletedservices/cloud-devops-test?api-version=2020-06-01-preview'

此外,您现在可以使用AZ CLI:

az apim deletedservice purge --help

示例:

az apim deletedservice purge -l APIM_LOCALTION -n APIM_NAME

相关内容

最新更新