The Parent Tag: cm-resource-parent for Azure cost management
Published Jan 31 2023 01:10 PM 10.3K Views
Microsoft

No, not the 1968 movie starring Haley Mills or the 1998 movie with Lindsay Lohan (depending on your vintage) - the parent tag is a new way to group related Microsoft Azure resources in Microsoft Cost Management + Billing. But wait, can’t you already combine resource costs by giving them the same tag name and value, like Application: Purchasing? Yes, you can, kind of … so let’s take a look at the difference.

 

Before I dive into HOW to add this tag to your Microsoft Azure resources, let me show you WHY you want to do this.

 

Meet the VMs

My demo environment was created with three virtual machines and associated resources, in three different resource groups:

Resource Group VM Related resources
SVM-01-RG VM-S19-01 VM, virtual network, public IP address, NSG, NIC, OS Disk, Data disk 1, Data disk 2, Bastion
SVM-02-RG VM-S19-02 VM, virtual network, public IP address, NSG, NIC, OS Disk, Data disk 1, Data disk 2, Bastion
SVM-03-RG VM-S19-03 VM, virtual network, public IP address, NSG, NIC, OS Disk, Data disk 1, Data disk 2, Bastion

 

Notice that's a mix of resources that are created by default with an Azure Virtual Machine (such as an OS disk and a network interface card/NIC), and some additional, optional resources (a public IP address and two data disks, attached to the VM).

 

VM-S19-01 has not been assigned any tags.

VM-S19-02 has its resource ID used as the value in the "cm-resource-parent" tag, which has been assigned to all of the related resources that we want to group, as being associated with this VM.

VM-S19-03 has all of its resources tagged with a name of "Server" and the value "03"

 

The scene is set, the actors are in place – roll film!

 

Cost analysis views

With the default Cost analysis pane view in Microsoft Cost Management + Billing, we can add a filter for a tag, but we have to select which tag value we are filtering on. Then we can group by Resource:

 

Azure Cost Analysis filtered on tag Server=03 and grouped by ResourceAzure Cost Analysis filtered on tag Server=03 and grouped by Resource

This is great for being able to see at a glance which resource is contributing the most to the total cost of $26.13 (shown as Actual Cost).

 

If we change the view type to a table, we get a breakdown:
Azure-Cost-Analysis-2-TagTable.jpg

 

But because of the filter, we’re only seeing resources with this one exact tag value. If we wanted to look at a different VM, we’d need to change the filter to the value we have used for its resources, as we can't do an OR filter combination.

 

So .. end scene. Let's now travel to the Cost Management Labs Cost Analysis preview. Here we’ll see our VMs in a slightly different setting, where the cm-resource-parent tag shines.

 

Cost analysis (preview)

By going to the Resources view of the Cost Analysis preview, we are presented with a table by default showing all the resources in this scope (our subscription), and our cm-resource-parent tagged resources are already rolled up to their parent. Note how the "server=03" tagged Bastion and Disk resources are listed separately:

The Azure Cost analysis (preview) view of resources, showing the cm-parent-resource grouped resourcesThe Azure Cost analysis (preview) view of resources, showing the cm-parent-resource grouped resources


 And expanding the arrow next to vm-s19-02 shows the detail under the rolled-up resources:

Microsoft Azure Cost Analysis (preview) showing resources and details that roll up to the total cost of a VM using the cm-parent-resource tagMicrosoft Azure Cost Analysis (preview) showing resources and details that roll up to the total cost of a VM using the cm-parent-resource tag

 

In the graphic above, all of the related resources that we tag roll up to the $27.77 cost of the vm-s19-02 virtual machine, and expanding the specific Virtual machine resource type shows the breakdown of those costs. Note you have a greater level of details showing about the cost meters or the Virtual machine resource type, compared to the previous table. We can further expand the Disk or Public IP address to get specific details about those resource charges too - that entire "sub table" shows all of the resources we tagged with cm-resource-parent and the resource ID of the VM.

 

While in my example I only have one set of VM resources using this tag, if I’d tagged all three VMs in the same manner (with the unique resource ID of each parent VM), I’d see all three VMs in the Cost Analysis preview with their total cost of all the related resources I'd chosen to include, grouped underneath – something I can’t achieve in the main Cost Analysis view.

 

Remember, this is not limited to virtual machines! Any resources in Azure with data you'd usually see in Cost Analysis, can be rolled up to group underneath a resource parent. Really useful for your application architectures, and the example in the official documentation (linked to in the Learn More section of this article) uses Azure Virtual Desktop (AVD) host pools. 

 

Where do I sign up?

Interested enough to want to explore this in your own environment? Go ahead and assign the cm-resource-parent tag with a value of the ResourceID you want to roll up to.  Just note, you will need to give Azure 24hrs to display the cost data in this format.

 

Visit this link for instructions on how to assign the tag via the Azure Portal

Via PowerShell
Remember how I didn't tag VM-S19-01 or it's related resources? I have a script for that! This script assumes that I want all of the resources that exist in the resource group of the VM, to be related to the VM as the resource parent.

 

 

 

 

 

 

 

$ResourceParent = "vm-s19-01"
$ParentID = Get-AzResource -Name $ResourceParent | Select-Object -ExpandProperty ResourceID
$RG = "SVM-01-RG"
$resourcelist = Get-AzResource -ResourceGroupName $RG 

foreach($item in $resourcelist){
    $tags = @{"cm-resource-parent"=$ParentID}
    Update-AzTag -ResourceId $item.ResourceId -Tag $tags -Operation Merge

}

 

 

 

 

 

 

 

 
Edit the $ResourceParent and $RG values to reflect your own environment. Note the -Operation Merge which will ADD this tag while preserving any existing ones that the resource already has.

Download this script and more from the ITOpsTalk GitHub repo: https://github.com/microsoft/ITOpsTalk

 

Via Azure Policy

Yes, you can use Azure Policy to assign tags to resources and that also works for the cm-parent-resource tag. I’ll let Microsoft’s Dean Cefola take center stage and show you how:

 

Feedback?

Go try this tag and submit your feedback - inside the Cost Analysis preview page, click on the button "How would you rate the cost analysis preview?" After selecting a number of stars, you'll see a pane where you can enter more details:
Giving feedback on the Microsoft Azure Cost Analysis previewGiving feedback on the Microsoft Azure Cost Analysis preview

 

Learn more:

Group related resources in the cost management preview

Microsoft Cost Management 2022 Year in review

Self paced training: Control Azure spending & manage bills with Microsoft Cost Management + Billing

 

2 Comments
Co-Authors
Version history
Last update:
‎Jun 18 2023 06:35 PM
Updated by: