Remove-AzureRmResource请求的资源不支持http方法'DELETE'

时间:2017-07-16 12:32:20

标签: azure arm-template

好的 - 我有一个奇怪的人......

我使用以下代码通过ARM模板部署了编译作业:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "compile-settings": {
        "type": "object",
        "metadata": {
            "description": "These are settings for a DSC Compile"
        }
    },
    "tag-values": {
        "type": "object",
        "metadata": {
            "description": "These are the Tag values"
        }
    }
},
"resources": [
    {
        "name": "[parameters('compile-settings').name]",
        "type": "Microsoft.Automation/automationAccounts/compilationjobs",
        "apiVersion": "2015-10-31",
        "location": "Australia Southeast",
        "tags": "[parameters('tag-values')]",
        "dependsOn": [],
        "properties": {
            "configuration": "[parameters('compile-settings').configuration]",
            "parameters": "[parameters('compile-settings').parameters]"
        },
        "resources": []
    }
],
"outputs": {}

}

因为我正在发展。当我重新运行部署时,我收到以下错误:

  

{     “代码”:“冲突”,     “message”:“具有指定ID的作业已存在。作业ID:cde3eb0e-e8e4-de3e-​​0eae-e4cde3eb0eae”   }

使用 resources.azure.com ,我找不到此资源,但在使用PowerShell时可以找到它,例如

Get-AzureRmResource -ResourceId "/subscriptions/{subscriptionId}/resourceGroups/rg-au-901/providers/Microsoft.Automation/automationAccounts/aa-au-901/compilationjobs/cde3eb0e-e8e4-de3e-0eae-e4cde3eb0eae" -ApiVersion "2015-10-31"

结果:

  

ResourceId:/subscriptions/{subscriptionId}/resourceGroups/rg-au-901/providers/Microsoft.Automation/automationAccounts/aa-au-901/compilationjobs/cde3eb0e-e8e4-de3e-​​0eae-e4cde3eb0eae   ResourceName:aa-au-901 / cde3eb0e-e8e4-de3e-​​0eae-e4cde3eb0eae   ResourceType:Microsoft.Automation / automationAccounts / compilationjobs   ResourceGroupName:rg-au-901   SubscriptionId:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx   属性:@ {jobId = cde3eb0e-e8e4-de3e-​​0eae-e4cde3eb0eae;创建时间= 2017-07-16T08:27:13.457 + 00:00; provisioningState =暂停;                       状态=暂停; statusDetails =无; STARTTIME = 2017-07-16T08:28:01.74 + 00:00; ENDTIME =;                       最后修改时间= 2017-07-16T08:28:13.85 + 00:00; lastStatusModifiedTime = 2017-07-16T08:28:13.85 + 00:00; exception =正在运行                       命令已停止,因为首选项变量“ErrorActionPreference”或common参数设置为Stop:该术语                       “xStorage \ xWaitforDisk”未被识别为cmdlet,函数,脚本文件或可运行程序的名称。检查                       拼写名称,或者如果包含路径,请验证路径是否正确,然后重试。参数=;配置=;                       的RunOn =; newNodeConfigurationBuildVersionRequired = FALSE}

但是,当我尝试使用带有 Force 参数的Remove-AzureRmResource删除它时,它会失败:

  

Remove-AzureRmResource:管道已停止。   在行:1个字符:1   + Remove-AzureRmResource -ResourceId“/ subscriptions / xxxxxxxx-xxxx-xxxx ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:CloseError:(:) [Remove-AzureRmResource],PipelineStoppedException       + FullyQualifiedErrorId:Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet   Remove-AzureRmResource:{“code”:“MethodNotAllowed”,“message”:“{\”Message \“:\”请求的资源不支持http方法'DELETE'。\“}”}   在行:1个字符:1   + Remove-AzureRmResource -ResourceId“/ subscriptions / xxxxxxxx-xxxx-xxxx ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:CloseError:(:) [Remove-AzureRmResource],ErrorResponseMessageException       + FullyQualifiedErrorId:MethodNotAllowed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet

帮助?

3 个答案:

答案 0 :(得分:1)

您可以使用PowerShell步骤来生成GUID,或者可以省略GUID,以便为自己生成一个GUID。

此外,还有一个powershell cmdlet来启动编译工作,不需要guid。

Start-AzureRmAutomationDscCompilationJob

答案 1 :(得分:0)

根据我的知识,您无法删除CompilationJob。再次执行作业时,它将重新生成不同的作业ID。您可以使用以下命令重新运行编译作业

Start-AzureRmAutomationDscCompilationJob -ResourceGroupName "shui" -AutomationAccountName "shuitest" -ConfigurationName "dscDomainJoin"

更多信息请参阅此link

如果要删除所有作业,则需要删除DSC配置。

答案 2 :(得分:0)

我实际上发布的答案是在错误中。如果已经存在相同的GUID,那么我就遇到了逻辑问题。

我发现我没有将子部署名称(总是不同的)传递给子部署,而ARM模板中的唯一字符串函数没有生成“唯一”GUID。

父模板中的资源现在具有以下代码:

"name": "[concat('dscCompile-', toLower(uniqueString(deployment().name)))]"

子模板使用变量,然后连接以创建唯一字符串以生成GUID。

"deployment": "[concat('-', toLower(uniqueString(deployment().name)))]"

"name": "[concat('newGuid', copyIndex(), variables('deployment'))]",

感谢所有回复了您的帮助和建议的人!