Azure creating budget using azure CLI with samples

Chandrakant Pawle 101 Reputation points
2024-08-29T16:53:31.0766667+00:00

Hello

Pls provide me Azure CLI code for creating budget alert.

Thanks

Regards

Chandrakant

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,697 questions
0 comments No comments
{count} votes

Accepted answer
  1. SadiqhAhmed-MSFT 46,206 Reputation points Microsoft Employee
    2024-08-30T17:08:58.0566667+00:00

    @Chandrakant Pawle Greetings!

    To create a budget alert using the Azure CLI, you'll need to use the az consumption budget command. This command lets you define a budget and set up alerts for when your spending approaches or exceeds your budget threshold. Source link - https://learn.microsoft.com/en-us/cli/azure/consumption/budget?view=azure-cli-latest

    Here is an example of how you can create a budget alert using Azure CLI:
    Ensure you have the Azure CLI installed and are logged in. You can log in using:

    az login

    Create a budget:

    az consumption budget create --amount 1000 \
      --time-grain monthly \
      --name MyBudget \
      --resource-group MyResourceGroup \
      --category cost \
      --start-date 2024-01-01 \
      --end-date 2024-12-31
    

    Create an action group:

    az monitor action-group create --resource-group MyResourceGroup \
      --name MyActionGroup \
      --short-name MyAG \
      --email-receiver name=myemail@example.com email=myemail@example.com
    

    Create a budget alert:

    az monitor metrics alert create --name MyBudgetAlert \
      --resource-group MyResourceGroup \
      --scopes /subscriptions/{subscription-id}/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM \
      --condition "total cost > 1000" \
      --action-group MyActionGroup
    

    Replace the placeholders with your actual values. This will create a budget of $1000 for the specified resource group, set up an action group to send email notifications, and create an alert that triggers when the budget is exceeded.

    You can refer to Azure budget documentation - https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/tutorial-acm-create-budgets?tabs=clibudget#create-and-edit-budgets

    Let us know if you need any further assistance!


    If the response helped, do "Accept Answer" and up-vote it

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.