azure 如何使用Terraform清除软删除的APIM?

ifsvaxew  于 2023-03-31  发布在  其他
关注(0)|答案(5)|浏览(194)

Azure API管理现在是“软删除”,以便在错误删除时恢复它。
Creating Azure API Management using deleted name results in name "already in use" error
当使用terraform destroy时,它会进行软删除,这使得开发变得棘手,因为您经常想要重新创建它。
如何使用terraform清除软删除的APIM?

bvpmtnay

bvpmtnay1#

遇到了同样的事情,我快速研究了如何调用这个API:

az rest --method delete --header "Accept=application/json" -u 'https://management.azure.com/subscriptions/{SubscriptionId}/providers/Microsoft.ApiManagement/locations/{eastus}/deletedservices/{api name}?api-version=2020-06-01-preview'
7uhlpewt

7uhlpewt2#

此功能已并入azurerm提供程序v2.77.0

qltillow

qltillow4#

您可以调用API来检查和删除下面的azure apims. scripts。
参考:-https://www.sharepointcollabs.com/2021/08/purging-soft-deleted-azure-apim-api.html

#GET请求-列出特定订阅中所有软删除的apim

$token = Get-AzAccessToken

$request = @{

Method = 'GET'

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

Headers = @{

    Authorization = "Bearer $($token.Token)"

 }

}

调用-静止方法@请求-输出文件c:\apimoutput.txt

#DELETE Request-这将清除软删除的apim

$token = Get-AzAccessToken

$request = @{

Method = 'DELETE'

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

Headers = @{

    Authorization = "Bearer $($token.Token)"

 }

}

Invoke-RestMethod @请求

lmvvr0a8

lmvvr0a85#

通过将purge_soft_delete_on_destroy设置为true来实现此目的。这是在提供程序级别完成的:

provider "azurerm" {
  features {
    api_management {
      purge_soft_delete_on_destroy = true
    }
  }
}

above answer引导我找到了解决方案。

相关问题