|
| 1 | +--- |
| 2 | +title: Quickstart - Create an Azure budget with Bicep |
| 3 | +description: Quickstart showing how to create a budget with Bicep. |
| 4 | +author: schaffererin |
| 5 | +ms.author: v-eschaffer |
| 6 | +ms.service: cost-management-billing |
| 7 | +ms.subservice: cost-management |
| 8 | +ms.topic: quickstart |
| 9 | +ms.date: 07/06/2022 |
| 10 | +ms.custom: subject-armqs, devx-track-azurepowershell, mode-arm |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Create a budget with Bicep |
| 14 | + |
| 15 | +Budgets in Cost Management help you plan for and drive organizational accountability. With budgets, you can account for the Azure services you consume or subscribe to during a specific period. They help you inform others about their spending to proactively manage costs and monitor how spending progresses over time. When the budget thresholds you've created are exceeded, notifications are triggered. None of your resources are affected and your consumption isn't stopped. You can use budgets to compare and track spending as you analyze costs. This quickstart shows you how to create a budget named 'MyBudget' using Bicep. |
| 16 | + |
| 17 | +[!INCLUDE [About Bicep](../../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 22 | + |
| 23 | +If you have a new subscription, you can't immediately create a budget or use other Cost Management features. It might take up to 48 hours before you can use all Cost Management features. |
| 24 | + |
| 25 | +Budgets are supported for the following types of Azure account types and scopes: |
| 26 | + |
| 27 | +- Azure role-based access control (Azure RBAC) scopes |
| 28 | + - Management groups |
| 29 | + - Subscription |
| 30 | +- Enterprise Agreement scopes |
| 31 | + - Billing account |
| 32 | + - Department |
| 33 | + - Enrollment account |
| 34 | +- Individual agreements |
| 35 | + - Billing account |
| 36 | +- Microsoft Customer Agreement scopes |
| 37 | + - Billing account |
| 38 | + - Billing profile |
| 39 | + - Invoice section |
| 40 | + - Customer |
| 41 | +- AWS scopes |
| 42 | + - External account |
| 43 | + - External subscription |
| 44 | + |
| 45 | +To view budgets, you need at least read access for your Azure account. |
| 46 | + |
| 47 | +For Azure EA subscriptions, you must have read access to view budgets. To create and manage budgets, you must have contributor permission. |
| 48 | + |
| 49 | +The following Azure permissions, or scopes, are supported per subscription for budgets by user and group. For more information about scopes, see [Understand and work with scopes](understand-work-scopes.md). |
| 50 | + |
| 51 | +- Owner: Can create, modify, or delete budgets for a subscription. |
| 52 | +- Contributor and Cost Management contributor: Can create, modify, or delete their own budgets. Can modify the budget amount for budgets created by others. |
| 53 | +- Reader and Cost Management reader: Can view budgets that they have permission to. |
| 54 | + |
| 55 | +For more information about assigning permission to Cost Management data, see [Assign access to Cost Management data](assign-access-acm-data.md). |
| 56 | + |
| 57 | +## No filter |
| 58 | + |
| 59 | +### Review the Bicep file |
| 60 | + |
| 61 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/create-budget-simple). |
| 62 | + |
| 63 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.consumption/create-budget-simple/main.bicep" ::: |
| 64 | + |
| 65 | +One Azure resource is defined in the Bicep file: |
| 66 | + |
| 67 | +- [Microsoft.Consumption/budgets](/azure/templates/microsoft.consumption/budgets): Create an Azure budget. |
| 68 | + |
| 69 | +### Deploy the Bicep file |
| 70 | + |
| 71 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 72 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 73 | + |
| 74 | + # [CLI](#tab/CLI) |
| 75 | + |
| 76 | + ```azurecli |
| 77 | + |
| 78 | +
|
| 79 | + az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails |
| 80 | + ``` |
| 81 | +
|
| 82 | + # [PowerShell](#tab/PowerShell) |
| 83 | +
|
| 84 | + ```azurepowershell |
| 85 | + |
| 86 | +
|
| 87 | + New-AzSubscriptionDeployment -Name demoSubDeployment -Location centralus -TemplateFile ./main.bicep -startDate "<start-date>" -endDate "<end-date>" -contactEmails $myContactEmails |
| 88 | + ``` |
| 89 | +
|
| 90 | + --- |
| 91 | +
|
| 92 | + You need to enter the following parameters: |
| 93 | +
|
| 94 | + - **startDate**: Replace **\<start-date\>** with the start date. It must be the first of the month in YYYY-MM-DD format. A future start date shouldn't be more than three months in the future. A past start date should be selected within the timegrain period. |
| 95 | + - **endDate**: Replace **\<end-date\>** with the end date in YYYY-MM-DD format. If not provided, it defaults to ten years from the start date. |
| 96 | + - **contactEmails**: First create a variable that holds your emails and then pass that variable. Replace the sample emails with the email addresses to send the budget notification to when the threshold is exceeded. |
| 97 | +
|
| 98 | + > [!NOTE] |
| 99 | + > When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 100 | +
|
| 101 | +## One filter |
| 102 | +
|
| 103 | +### Review the Bicep file |
| 104 | +
|
| 105 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/create-budget-onefilter). |
| 106 | +
|
| 107 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.consumption/create-budget-onefilter/main.bicep" ::: |
| 108 | +
|
| 109 | +One Azure resource is defined in the Bicep file: |
| 110 | +
|
| 111 | +- [Microsoft.Consumption/budgets](/azure/templates/microsoft.consumption/budgets): Create an Azure budget. |
| 112 | +
|
| 113 | +### Deploy the Bicep file |
| 114 | +
|
| 115 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 116 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 117 | +
|
| 118 | + # [CLI](#tab/CLI) |
| 119 | +
|
| 120 | + ```azurecli |
| 121 | + |
| 122 | + myRgFilterValues ='("resource-group-01", "resource-group-02")' |
| 123 | +
|
| 124 | + az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails resourceGroupFilterValues=$myRgFilterValues |
| 125 | + ``` |
| 126 | +
|
| 127 | + # [PowerShell](#tab/PowerShell) |
| 128 | +
|
| 129 | + ```azurepowershell |
| 130 | + |
| 131 | + $myRgFilterValues = @("resource-group-01", "resource-group-02") |
| 132 | +
|
| 133 | + New-AzSubscriptionDeployment -Name demoSubDeployment -Location centralus -TemplateFile ./main.bicep -startDate "<start-date>" -endDate "<end-date>" -contactEmails $myContactEmails -resourceGroupFilterValues $myRgFilterValues |
| 134 | + ``` |
| 135 | +
|
| 136 | + --- |
| 137 | +
|
| 138 | + You need to enter the following parameters: |
| 139 | +
|
| 140 | + - **startDate**: Replace **\<start-date\>** with the start date. It must be the first of the month in YYYY-MM-DD format. A future start date shouldn't be more than three months in the future. A past start date should be selected within the timegrain period. |
| 141 | + - **endDate**: Replace **\<end-date\>** with the end date in YYYY-MM-DD format. If not provided, it defaults to ten years from the start date. |
| 142 | + - **contactEmails**: First create a variable that holds your emails and then pass that variable. Replace the sample emails with the email addresses to send the budget notification to when the threshold is exceeded. |
| 143 | + - **resourceGroupFilterValues** First create a variable that holds your resource group filter values and then pass that variable. Replace the sample filter values with the set of values for your resource group filter. |
| 144 | +
|
| 145 | + > [!NOTE] |
| 146 | + > When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 147 | +
|
| 148 | +## Two or more filters |
| 149 | +
|
| 150 | +### Review the Bicep file |
| 151 | +
|
| 152 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/create-budget). |
| 153 | +
|
| 154 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.consumption/create-budget/main.bicep" ::: |
| 155 | +
|
| 156 | +One Azure resource is defined in the Bicep file: |
| 157 | +
|
| 158 | +- [Microsoft.Consumption/budgets](/azure/templates/microsoft.consumption/budgets): Create an Azure budget. |
| 159 | +
|
| 160 | +### Deploy the Bicep file |
| 161 | +
|
| 162 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 163 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 164 | +
|
| 165 | + # [CLI](#tab/CLI) |
| 166 | +
|
| 167 | + ```azurecli |
| 168 | + |
| 169 | + myContactGroups ='("action-group-resource-id-01", "action-group-resource-id-02")' |
| 170 | + myRgFilterValues ='("resource-group-01", "resource-group-02")' |
| 171 | + myMeterCategoryFilterValues ='("meter-category-01", "meter-category-02")' |
| 172 | +
|
| 173 | + az deployment sub create --name demoSubDeployment --location centralus --template-file main.bicep --parameters startDate=<start-date> endDate=<end-date> contactEmails=$myContactEmails contactGroups=$myContactGroups resourceGroupFilterValues=$myRgFilterValues meterCategoryFilterValues=$myMeterCategoryFilterValues |
| 174 | + ``` |
| 175 | +
|
| 176 | + # [PowerShell](#tab/PowerShell) |
| 177 | +
|
| 178 | + ```azurepowershell |
| 179 | + |
| 180 | + $myContactGroups = @("action-group-resource-id-01", "action-group-resource-id-02") |
| 181 | + $myRgFilterValues = @("resource-group-01", "resource-group-02") |
| 182 | + $myMeterCategoryFilterValues = @("meter-category-01", "meter-category-02") |
| 183 | +
|
| 184 | +
|
| 185 | + New-AzSubscriptionDeployment -Name demoSubDeployment -Location centralus -TemplateFile ./main.bicep -startDate "<start-date>" -endDate "<end-date>" -contactEmails $myContactEmails -contactGroups $myContactGroups -resourceGroupFilterValues $myRgFilterValues -meterCategoryFilterValues $myMeterCategoryFilterValues |
| 186 | + ``` |
| 187 | +
|
| 188 | + --- |
| 189 | +
|
| 190 | + You need to enter the following parameters: |
| 191 | +
|
| 192 | + - **startDate**: Replace **\<start-date\>** with the start date. It must be the first of the month in YYYY-MM-DD format. A future start date shouldn't be more than three months in the future. A past start date should be selected within the timegrain period. |
| 193 | + - **endDate**: Replace **\<end-date\>** with the end date in YYYY-MM-DD format. If not provided, it defaults to ten years from the start date. |
| 194 | + - **contactEmails**: First create a variable that holds your emails and then pass that variable. Replace the sample emails with the email addresses to send the budget notification to when the threshold is exceeded. |
| 195 | + - **contactGroups**: First create a variable that holds your contact groups and then pass that variable. Replace the sample contact groups with the list of action groups to send the budget notification to when the threshold is exceeded. |
| 196 | + - **resourceGroupFilterValues**: First create a variable that holds your resource group filter values and then pass that variable. Replace the sample filter values with the set of values for your resource group filter. |
| 197 | + - **meterCategoryFilterValues**: First create a variable that holds your meter category filter values and then pass that variable. Replace the sample filter values within parentheses with the set of values for your meter category filter. |
| 198 | +
|
| 199 | + > [!NOTE] |
| 200 | + > When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 201 | +
|
| 202 | +## Review deployed resources |
| 203 | +
|
| 204 | +Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group. |
| 205 | +
|
| 206 | +# [CLI](#tab/CLI) |
| 207 | +
|
| 208 | +```azurecli-interactive |
| 209 | +az consumption budget list |
| 210 | +``` |
| 211 | + |
| 212 | +# [PowerShell](#tab/PowerShell) |
| 213 | + |
| 214 | +```azurepowershell-interactive |
| 215 | +Get-AzConsumptionBudget |
| 216 | +``` |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +## Clean up resources |
| 221 | + |
| 222 | +When you no longer need the budget, use the Azure portal, Azure CLI, or Azure PowerShell to delete it: |
| 223 | + |
| 224 | +# [CLI](#tab/CLI) |
| 225 | + |
| 226 | +```azurecli-interactive |
| 227 | +az consumption budget delete --budget-name MyBudget |
| 228 | +``` |
| 229 | + |
| 230 | +# [PowerShell](#tab/PowerShell) |
| 231 | + |
| 232 | +```azurepowershell-interactive |
| 233 | +Remove-AzConsumptionBudget -Name MyBudget |
| 234 | +``` |
| 235 | + |
| 236 | +--- |
| 237 | + |
| 238 | +## Next steps |
| 239 | + |
| 240 | +In this quickstart, you created an Azure budget and deployed it using Bicep. To learn more about Cost Management and Billing and Bicep, continue on to the articles below. |
| 241 | + |
| 242 | +- Read the [Cost Management and Billing](../cost-management-billing-overview.md) overview. |
| 243 | +- [Create budgets](tutorial-acm-create-budgets.md) in the Azure portal. |
| 244 | +- Learn more about [Bicep](../../azure-resource-manager/bicep/overview.md). |
0 commit comments