When starting With Azure The Costs are important. If you have created a lot of resources you might want to know who owns the resources or what is the purpose of this resource.
Resource management: Your IT teams will need to quickly locate resources associated with specific workloads, environments, ownership groups, or other important information. Organizing resources is critical to assigning organizational roles and access permissions for resource management.
Tagging resources is the way to find the resource and keep it with the purpose that you used it for. but over time things may change or added.
There are tons of reasons why you should use Tagging
- Cost management and optimization
- Cloud accounting models
- ROI calculations
- Cost tracking
- Budgets
- Alerts
- Recurring spend tracking and reporting
- Post-implementation optimizations
- Cost-optimization tactics
- Operations management
- Security
- Governance and regulatory compliance
- Automation
- Workload optimization
That way items in your resource groups may be un tagged. You can set policys for this but when there is some wild resource you might wan to check it first be for tagging.
As you can see the TAG’s are not applied to all the resources.
When you check the cost on the tag or on the resource group you will see different numbers. For adding the tag to all resources in the Resource group We use a PowerShell line.
First we connect to the Azure subscription or use the CLI
Connect-AzAccount
Login-AzAccount
Get-AzSubscription
Select-AzSubscription -Subscription "Microsoft Azure”
We select the resource group.
$RG = "rsmvprsg01"
When we check that resource group it has a tag. So there is no need to set an tag unless you want to set an extra tag to the resources.
Now We are setting the tag to all the resources that are in the resource group. Get-azresourcegroup and set the TAG.
$group = Get-AzResourceGroup -Name $rg
Get-AzResource -ResourceGroupName $group.ResourceGroupName | ForEach-Object {Set-AzResource -ResourceId $_.ResourceId -Tag $group.Tags -Force }
When looking in the Billing you might not see this directly
Drilling down on the resource you can see it is set.
If you did not had set the Tags then you need to define a tag first.
#Force Tags to all resources
#set tag no pre defined
Set-AzResourceGroup -Name $rg -Tag @{ env="Robert Smit"; RSM="ClusterMVP" }
- Define what each tag should be used to identify. Tag name : The exact term used for the tag, e.g. “Application” , “Department” , “Project”
Values: List all potential values for each tag name, e.g. “finance”, “website” , “name” - Tag names can have up to 512 characters, values can have up to 256
- These characters aren’t supported with tags: < > % & / ?
$group = Get-AzResourceGroup -Name $rg
Get-AzResource -ResourceGroupName $group.ResourceGroupName | ForEach-Object {Set-AzResource -ResourceId $_.ResourceId -Tag $group.Tags -Force }
And you can do this also with the Azure CLI
Open the CLI in the Azure portal
I’ll use the same settings
env="Robert Smit"; RSM="ClusterMVP"
az tag create –name Env
az tag add-value –name Env –value "Robert Smit”
Now that the Tags are created we can add them to a resource group
az group update -n rsmdemo01–set tags.Env="Robert Smit" tags.MVP=ClusterMVP
Is sett two tags but you can set just one or multiple.
Enforce tagging rules with Azure policies can done easily as there are many examples here https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-policies
Assign policies for tag compliance
The Link will take you to the Github repository https://github.com/Azure/azure-policy
Follow Me on Twitter @ClusterMVP
Follow My blog https://robertsmit.wordpress.com
Linkedin Profile Robert Smit MVP Linkedin profile
Google : Robert Smit MVP profile