首页 文章

AZURE资源管理器:清理资源组

提问于
浏览
0

TL;DR:

有没有办法删除资源组中的所有资源,但具有空模板的完整模式部署和从Web界面手动逐步删除除外?

删除资源组不是一个选项(访问权限:贡献者,而不是所有者)

Details:

我想在AZURE中彻底清理资源组 .

删除资源组不是一个选项(访问权限:贡献者,而不是所有者)

最优雅和明显的方法(在一些文章中也有描述)是使用“空”部署模板执行完全部署:

New-AzureRmResourceGroupDeployment -Mode Complete -ResourceGroupName RG_NAME -TemplateFile .\empty.json

使用以下empty.json:

{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "2018-02-15", "parameters": {}, "variables": {}, "resources": [], "outputs": {} }

但是......这有时会起作用 . 甚至不是 most .

一旦它获得无限循环试图删除SQL Server,失败并尝试再次删除 . 等了20分钟后,我参加了活动,发现了大约100个活动

“删除SQL Server已启动”...“已接受”...“失败”...“已启动”...“已接受”...“已失败”......

你明白了 .

其他时候它工作正常 .

所以,问题是: is there a way to delete all resources in resource group except for Complete-mode deploy with empty template and manual step-by-step deletion from web interface?

Example that seems to be repeatable

  • 尝试使用以下模板部署SQL Server(它将通过密码复杂性验证失败)

{"$schema":“http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json# ", " contentVersion ": " 2018年2月19日", "参数": { "位置": { "型": "串", "默认值": "西欧" }, " dbAdministratorLogin ": { "型": "串", "默认值": " SYSADM " }, " dbAdministratorPassword ": { "键入": "串" , "默认值": " 123123个" }, }, "变量": { " DBSERVERNAME ": " dka-tst-sto-sql-srv ", " databaseName ": " dka-tst-sto-sql " }, " resources ": [ {" comments ": " server and database . 数据库 - 服务器的子资源", " type ": " Microsoft.Sql / servers ", " name ": " [variables( 'dbServerName')] ", " apiVersion ": " 2015-05-01-preview ", " location ": " [parameters('location')] ", " properties ": { " administratorLogin ": " [parameters('dbAdministratorLogin')] ", " administratorLoginPassword ": " [parameters('dbAdministratorPassword')] ", "版本": " 12.0 " }, "资源": [{ "类型": "数据库", "名称": " [变量('databaseName')] ", " apiVersion ": " 2014年4月1日预览", "位置": " [参数('location')] ", "性质": { "核对": " SQL_Latin1_General_CP1_CI_AS ", "版": "标准", " maxSizeBytes ": " 268435456000 ", " requestedServiceObjectiveId ": " f1173c43-91bd-4AAA-973C-54e79e15235b ", " sampleName ": " ", " zoneRedundant ": false }, " dependsOn ": [ " [CONCAT('Microsoft.Sql/servers/',变量('dbServerName'))] " ] }, { "型": " firewallrules ", "名称": " AllowAllWindowsAzureIps ", " apiVersion ": " 2014年4月1日,预览", " location ": " [parameters('location')] ", " properties ": { " endIpAddress ": " 0.0.0.0 ", " startIpAddress ": " 0.0.0.0 " }, " dependsOn ": [ " [concat('Microsoft.Sql/servers/',variables('dbServerName'))] " ] } ] } ], " ou tputs“:{}}

然后尝试使用“空”模板删除 .

您将获得无限循环的DB删除“已启动..接受..失败..已启动..已接受..已失败...已启动...”

1 回答

  • 1

    第一个也是最明显的方法:删除资源组 . 重新创建它需要5秒,空资源组不值得,你可以脚本标签\权限重新应用它们 .

    另一种方式可能是这样的:

    Get-AzureRmResource | ? ResourceGroupName -eq your_resource_group_name | Remove-AzureRmResource -WhatIf
    

    如果您确信这仅针对您想要的资源,则可以删除 -WhatIf . 您还可以使用 -AsJob 加速删除

相关问题