Skip to content

Commit 50c3887

Browse files
authored
Update tutorial-acm-create-budgets.md
1 parent c4c3655 commit 50c3887

File tree

1 file changed

+175
-3
lines changed

1 file changed

+175
-3
lines changed

articles/cost-management-billing/costs/tutorial-acm-create-budgets.md

Lines changed: 175 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ To receive mobile push notifications when your budget threshold is met, you can
178178
179179
:::image type="content" source="./media/tutorial-acm-create-budgets/azure-app-budgets.png" alt-text="Screenshot showing budgets in the Azure app." lightbox="./media/tutorial-acm-create-budgets/azure-app-budgets.png" :::
180180

181-
## Create and edit budgets with PowerShell
181+
## Create and edit budgets
182+
183+
### [PowerShell](#tab/psbudget)
182184

183185
If you're an EA customer, you can create and edit budgets programmatically using the Azure PowerShell module. However, we recommend that you use REST APIs to create and edit budgets because CLI commands might not support the latest version of the APIs.
184186

@@ -191,7 +193,7 @@ To download the latest version of Azure PowerShell, run the following command:
191193
install-module -name Az
192194
```
193195

194-
The following example commands create a budget.
196+
The following example commands create a budget using PowerShell. Make sure to replace all example prompts with your own info.
195197

196198
```azurepowershell-interactive
197199
#Sign into Azure PowerShell with your account
@@ -213,10 +215,180 @@ Get-AzContext
213215
New-AzConsumptionBudget -Amount 100 -Name TestPSBudget -Category Cost -StartDate 2020-02-01 -TimeGrain Monthly -EndDate 2022-12-31 -ContactEmail [email protected] -NotificationKey Key1 -NotificationThreshold 0.8 -NotificationEnabled -ContactGroup $ActionGroupId
214216
```
215217

216-
## Create a budget with an Azure Resource Manager template
218+
### [CLI](#tab/clibudget)
219+
220+
The following example creates a budget using Azure CLI. Make sure to replace all example prompts with your own info.
221+
222+
```azurecli
223+
# Sign into Azure CLI with your account
224+
az login
225+
226+
# Select a subscription to monitor with a budget
227+
az account set --subscription "Your Subscription"
228+
229+
# Create an action group email receiver and corresponding action group
230+
email1=$(az monitor action-group receiver email create --email-address [email protected] --name EmailReceiver1 --resource-group YourResourceGroup --query id -o tsv)
231+
ActionGroupId=$(az monitor action-group create --resource-group YourResourceGroup --name TestAG --short-name TestAG --receiver $email1 --query id -o tsv)
232+
233+
# Create a monthly budget that sends an email and triggers an Action Group to send a second email.
234+
# Make sure the StartDate for your monthly budget is set to the first day of the current month.
235+
# Note that Action Groups can also be used to trigger automation such as Azure Functions or Webhooks.
236+
az consumption budget create --amount 100 --name TestCLIBudget --category Cost --start-date "2020-02-01" --time-grain Monthly --end-date "2022-12-31" --contact-email [email protected] --notification-key Key1 --notification-threshold 0.8 --notification-enabled --contact-group $ActionGroupId
237+
```
238+
239+
### [Terraform](#tab/tfbudget)
240+
241+
Make sure to properly [install and configure Terraform](/developer/terraform/quickstart-configure) before continuing. All examples are based on [HashiCorp's 'azurerm_subscription_cost_management_export' docs](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subscription_cost_management_export).
242+
243+
The following example creates a budget using Terraform. Make sure to replace all example prompts with your own info.
244+
245+
1. Configure provider: Ensure you have the Azure provider configured.
246+
```
247+
provider "azurerm" {
248+
features {}
249+
}
250+
```
251+
252+
1. Select an Azure subscription: Specify the subscription ID in the provider configuration or via environment variables.
253+
```
254+
data "azurerm_subscription" "example" {}
255+
```
256+
257+
1. Create a resource group.
258+
```
259+
resource "azurerm_resource_group" "example" {
260+
name = "example-resources"
261+
location = "West Europe"
262+
}
263+
264+
```
265+
1. Set up an action group for notifications.
266+
267+
```
268+
resource "azurerm_monitor_action_group" "example" {
269+
name = "TestAG"
270+
resource_group_name = azurerm_resource_group.example.name
271+
short_name = "TestAG"
272+
273+
email_receiver {
274+
name = "EmailReceiver1"
275+
email_address = "[email protected]"
276+
use_common_alert_schema = true
277+
}
278+
}
279+
280+
```
281+
282+
1. Create a storage account.
283+
```
284+
resource "azurerm_storage_account" "example" {
285+
name = "examplestoracc"
286+
resource_group_name = azurerm_resource_group.example.name
287+
location = azurerm_resource_group.example.location
288+
account_tier = "Standard"
289+
account_replication_type = "LRS"
290+
}
291+
292+
```
293+
294+
1. Create a storage container.
295+
```
296+
resource "azurerm_storage_container" "example" {
297+
name = "examplecontainer"
298+
storage_account_name = azurerm_storage_account.example.name
299+
}
300+
```
301+
302+
1. Set up subscription cost management export.
303+
```
304+
resource "azurerm_subscription_cost_management_export" "example" {
305+
name = "exampleexport"
306+
subscription_id = data.azurerm_subscription.example.id
307+
recurrence_type = "Monthly"
308+
recurrence_period_start_date = "2020-08-18T00:00:00Z"
309+
recurrence_period_end_date = "2020-09-18T00:00:00Z"
310+
311+
export_data_storage_location {
312+
container_id = azurerm_storage_container.example.resource_manager_id
313+
root_folder_path = "/root/updated"
314+
}
315+
316+
export_data_options {
317+
type = "Usage"
318+
time_frame = "WeekToDate"
319+
}
320+
}
321+
322+
```
323+
324+
1. Apply the terraform configuration
325+
326+
Here's the full code if you'd like to modify it directly from source instead of piecing it together through the steps.
327+
328+
```
329+
provider "azurerm" {
330+
features {}
331+
}
332+
333+
data "azurerm_subscription" "example" {}
334+
335+
resource "azurerm_resource_group" "example" {
336+
name = "example-resources"
337+
location = "West Europe"
338+
}
339+
340+
resource "azurerm_monitor_action_group" "example" {
341+
name = "TestAG"
342+
resource_group_name = azurerm_resource_group.example.name
343+
short_name = "TestAG"
344+
345+
email_receiver {
346+
name = "EmailReceiver1"
347+
email_address = "[email protected]"
348+
use_common_alert_schema = true
349+
}
350+
}
351+
352+
resource "azurerm_storage_account" "example" {
353+
name = "examplestoracc"
354+
resource_group_name = azurerm_resource_group.example.name
355+
356+
location = azurerm_resource_group.example.location
357+
account_tier = "Standard"
358+
account_replication_type = "LRS"
359+
}
360+
361+
resource "azurerm_storage_container" "example" {
362+
name = "examplecontainer"
363+
storage_account_name = azurerm_storage_account.example.name
364+
}
365+
366+
resource "azurerm_subscription_cost_management_export" "example" {
367+
name = "exampleexport"
368+
subscription_id = data.azurerm_subscription.example.id
369+
recurrence_type = "Monthly"
370+
recurrence_period_start_date = "2020-08-18T00:00:00Z"
371+
recurrence_period_end_date = "2020-09-18T00:00:00Z"
372+
373+
export_data_storage_location {
374+
container_id = azurerm_storage_container.example.resource_manager_id
375+
root_folder_path = "/root/updated"
376+
}
377+
378+
export_data_options {
379+
type = "Usage"
380+
time_frame = "WeekToDate"
381+
}
382+
}
383+
384+
```
385+
386+
### [Azure Resource Manager template](#tab/armbudget)
217387

218388
You can create a budget using an Azure Resource Manager template. To use the template, see [Create a budget with an Azure Resource Manager template](quick-create-budget-template.md).
219389

390+
---
391+
220392
## Clean up resources
221393

222394
If you created a budget and you no longer need it, view its details and delete it.

0 commit comments

Comments
 (0)