Apply inventory tagging to Azure Arc enabled servers
This article provides guidance on how to use Azure Arc enabled servers to provide server inventory management capabilities across hybrid multicloud and on-premises environments.
Azure Arc enabled servers enable you to manage your Windows and Linux machines hosted outside of Azure on your corporate network or other cloud providers. This is similar to how you manage native virtual machines in Azure. When a hybrid machine is connected to Azure, it becomes a connected machine and is treated as a resource in Azure. Each connected machine has a resource ID, is managed as part of a resource group inside a subscription, and benefits from standard Azure constructs such as Azure Policy and applying tags. The ability to easily organize and manage server inventory using Azure as a management engine greatly reduces administrative complexity and provides a consistent strategy for hybrid and multicloud environments.
The procedures in this article assumes you've already deployed VMs, or servers that are running on-premises or on other clouds, and you have connected them to Azure Arc. If you haven't, the following information can help you automate this.
- GCP Ubuntu instance
- GCP Windows instance
- AWS Ubuntu EC2 instance
- AWS Amazon Linux 2 EC2 instance
- VMware vSphere Ubuntu VM
- VMware vSphere Windows Server VM
- Vagrant Ubuntu box
- Vagrant Windows box
Clone the Azure Arc Jumpstart repository.
git clone https://github.com/microsoft/azure_arc
Install or update Azure CLI to version 2.7 or later. Use the following command to check the current installed version.
Verify that your Azure Arc connected servers are ready for tagging
Use Resource Graph Explorer to query and view resources in Azure.
Enter Resource Graph Explorer in the top search bar in the Azure portal and select it.
In the query window, enter the following query, and then select Run Query:
Resources | where type =~ 'Microsoft.HybridCompute/machines'
If you have correctly created Azure Arc enabled servers, they are listed in the results pane of Resource Graph Explorer. You can also view the Azure Arc enabled serves from the Azure portal.
Create a basic Azure tag taxonomy
Open Azure CLI and run the following commands to create a basic taxonomy structure that lets you easily query and report on where your server resources are hosted (whether in Azure, AWS, GCP, or on-premises). For more guidance on building out a tag taxonomy please review the resource naming and tagging decision guide.
az tag create --name "Hosting Platform" az tag add-value --name "Hosting Platform" --value "Azure" az tag add-value --name "Hosting Platform" --value "AWS" az tag add-value --name "Hosting Platform" --value "GCP" az tag add-value --name "Hosting Platform" --value "On-premises"
Tag your Azure Arc resources
After you've created a basic taxonomy structure, apply tags to the Azure Arc enabled server resources. The following procedure demonstrates tagging resources in both AWS and GCP. If you only have resources in one of these providers, you can skip to the appropriate section for AWS or GCP.
Tag the Azure Arc connected AWS Ubuntu EC2 instance
In CLI, run the following commands to apply the
Hosting Platform : AWS tag to your AWS Azure Arc enabled servers.
If you connected your AWS EC2 instances using a method other than the one described in the Azure tutorial, then you need to adjust the values for
awsMachineName to match values specific to your environment.
export awsResourceGroup="arc-aws-demo" export awsMachineName="arc-aws-demo" export awsMachineResourceId="$(az resource show --resource-group $awsResourceGroup --name $awsMachineName --resource-type "Microsoft.HybridCompute/machines" --query id)" export awsMachineResourceId="$(echo $awsMachineResourceId | tr -d "\"" | tr -d '\r')" az resource tag --ids $awsMachineResourceId --tags "Hosting Platform"="AWS"
Tag Azure Arc connected GCP Ubuntu server
In CLI, run the following commands to apply the
Hosting Platform : GCP tag to your GCP Azure Arc enabled servers.
If you connected your GCP instances using a method other than the one described in the related Azure Arc Terraform tutorial, then you will need to adjust the values for
gcpMachineName to match values specific to your environment.
export gcpResourceGroup="arc-gcp-demo" export gcpMachineName="arc-gcp-demo" export gcpMachineResourceId="$(az resource show --resource-group $gcpResourceGroup --name $gcpMachineName --resource-type "Microsoft.HybridCompute/machines" --query id)" export gcpMachineResourceId="$(echo $gcpMachineResourceId | tr -d "\"" | tr -d '\r')" az resource tag --resource-group $gcpResourceGroup --ids $gcpMachineResourceId --tags "Hosting Platform"="GCP"
Query resources by tag using Resource Graph Explorer
After you apply tags to the resources that are hosted in multiple clouds, use Resource Graph Explorer to query them and get insight into your multicloud landscape.
In the query window, enter the following query:
Resources | where type =~ 'Microsoft.HybridCompute/machines' | where isnotempty(tags['Hosting Platform']) | project name, location, resourceGroup, tags
Click Run Query and then select the Formatted Results toggle. If done correctly, you should see all Azure Arc enabled servers and their assigned
Hosting Platformtag values.
We can also view the tags on the projected servers from Azure portal.
Clean up your environment
Complete the following steps to clean up your environment.
Remove the virtual machines from each environment by following the teardown instructions from each guide.
Remove tags created as part of this guide by executing the following script in Azure CLI.
az tag remove-value --name "Hosting Platform" --value "Azure" az tag remove-value --name "Hosting Platform" --value "AWS" az tag remove-value --name "Hosting Platform" --value "GCP" az tag remove-value --name "Hosting Platform" --value "On-premises" az tag create --name "Hosting Platform"