Apply and manage tags on resources

Manage Azure subscriptions and governance

📘Microsoft Certified: Azure Administrator Associate (AZ-104)


1. What Are Tags?

In Azure, a tag is a name-value pair that you can apply to resources, resource groups, or subscriptions. Think of it as a label you attach to a resource to describe it.

  • Name: The key or category of the tag.
  • Value: The description or detail for that tag.

Example:

  • Name: Environment
  • Value: Production

Purpose: Tags help you organize, manage, and report on resources. They don’t affect how a resource works, but they are critical for governance and management.


2. Why Are Tags Important in an IT Environment?

Tags are widely used in IT for resource management, billing, and automation:

  1. Cost Management:
    • You can group resources by tags like Department or Project to track costs.
    • Example: Tag all resources used by the “HR Department” with Department: HR.
  2. Resource Organization:
    • With thousands of resources, tags help categorize by environment (Dev, Test, Prod) or application.
  3. Automation & Governance:
    • Scripts or Azure Policies can automatically act on resources with specific tags.
    • Example: Automatically back up all resources with Backup: Daily.
  4. Compliance & Reporting:
    • Tags help ensure resources meet organizational policies.
    • Example: Tag all resources that store sensitive data with Compliance: GDPR.

3. How to Apply Tags

a) Azure Portal

  1. Go to the resource or resource group.
  2. Click Tags in the left-hand menu.
  3. Add a Name and Value.
  4. Click Save.

Note: You can tag individual resources, or apply the same tags to an entire resource group for efficiency.


b) Azure CLI

# Add a tag to a resource
az tag create --name Environment --values Production

# Add a tag directly to a resource
az resource tag --tags Environment=Production --name MyVM --resource-group MyResourceGroup

c) Azure PowerShell

# Set a tag on a resource
Set-AzResource -ResourceGroupName "MyResourceGroup" -ResourceName "MyVM" -Tag @{Environment="Production"} -Force

4. Managing Tags

a) Update Tags

  • You can modify existing tags to update values or change names.
  • Example: Change Environment: Dev to Environment: Test.

b) Delete Tags

  • Remove a tag completely from a resource.
  • Example: If a project ends, remove Project: ProjectX.

c) Inheritance

  • Tags do not automatically propagate to resources in a resource group, unless you explicitly apply them at the group level.
  • Policies or scripts are used if you want automatic tagging for all resources.

5. Best Practices for Tags

  1. Use a Standard Naming Convention:
    • Keep it consistent, e.g., Environment, Owner, CostCenter.
  2. Limit Tag Count:
    • Azure allows 50 tags per resource. Don’t overuse tags.
  3. Use for Cost and Management:
    • Always use tags to track cost, ownership, and environment.
  4. Automate with Policies:
    • Use Azure Policy to enforce tagging rules. Example: Every resource must have a CostCenter tag.

6. Tag Reporting

  • Azure Cost Management + Billing allows you to filter and group costs by tags.
  • Example: See total cost of resources for Department: Finance.
  • This is exam-relevant because Microsoft tests your ability to use tags for management and governance.

Key Exam Points to Remember

  1. Tags are name-value pairs for resources.
  2. Tags help with organization, cost tracking, and automation.
  3. Tags can be applied using:
    • Azure Portal
    • Azure CLI
    • PowerShell
  4. Tags can be added, updated, or removed.
  5. Tags don’t automatically propagate unless policies or scripts are used.
  6. Best practice: use consistent naming, limit number, and enforce with Azure Policy.
  7. Cost Management and governance heavily rely on tagging.

Leave a Reply

Your email address will not be published. Required fields are marked *

Buy Me a Coffee