Search code examples
azurecommand-line-interfaceazure-rm-templateunauthorized

Azure Budget ARM template deployment unauthorized


I am trying to deploy an ARM template containing an Azure budget. Currently I'm using the Azure CLI but it happens via the portal also.

az deployment group create --resource-group my-rg --template-file c:\dev\arm_template.json

I would like to know what the solution is to avoid the following error:

Deployment failed. Correlation ID: 10cfac68-3ce9-4527-bee8-df48a761f965. {

  "error": {

    "code": "401",

    "message": "Unauthorized. Request ID: 4c5ee5cb-4b71-4c8b-8965-f3b89cdd2c8a"

  }

}

Solution

  • I had the exact same issue, ended up being the filter, if the filter is not set correctly, then the budget tries to apply to your subscription and not just the resource group or whatever you are targeting

    {
      "name": "[variables('budgetName')]",
      "type": "Microsoft.Consumption/budgets",
      "apiVersion": "2019-10-01",
      "properties": {
        "timePeriod": {
          "startDate": "2020-09-01T00:00:00Z",
          "endDate": "2028-07-01T00:00:00Z"
        },
        "timeGrain": "Monthly",
        "amount": 40,
        "currentSpend": null,
        "category": "Cost",
        "notifications": {
          "GreaterThan80": {
            "enabled": true,
            "operator": "GreaterThan",
            "threshold": 80,
            "contactEmails": [],
            "contactRoles": [],
            "contactGroups": [
              "[resourceId('Microsoft.Insights/actionGroups',variables('actionGroupName'))]"
            ]
          }
        },
        "filter": {
          "dimensions": {
            "name": "ResourceGroupName",
            "operator": "In",
            "values": [ "variables('resourceGroup')" ]
          }
        }
      }
    }