Using Tags In Azure
Think you can do better? Show us!
Sometimes finding and sorting items in Azure can be a real pain. In this video we look at Tags as a way of classifying resources in the way we want, so that we can find and sort them better. We look at how we do this in the portal, and why this is useful. Then we move on to discover how Powershell can add some goodness with cmdlets such as Get-AzureRmTag and Set-AzureRmResource.
this snippet, we're going to look at tags in Azure how to apply them and why they useful. So here in Azure console. If we look at our virtual machines and drill down into the settings of those. We're noticing the left hand side. There's a tags option here. If you click on that. You'll see 2 freeform boxes, which allows us to apply tags. If I just create one called billing. Click on save. And quite another one cause Department. I click on save. And if we go back to our virtual machines. And apply some tags to the second virtual machine here going to tags. We're notice if we click the drop down here. We've already created these tags are they appear in the list for us. On this one, I'm going to go with billing and I'm going to select company one back, she want this to be company, too, so I edit it. Click on save and do the same for Department. Going to that an add in these sales Department. When I click on save and if we go back to our list of virtual machines were notice. We've got an edit columns section at the top here click on that we should be able to scroll down and add in a tags column. At that in click on apply. Have a column on the right hand side here. That shows us the tags. We've got. And if we scroll over that will see the tooltips will come up and show us, the tags. We could also go in here. And edit the tags. So here I want to change finance to buy T say, and then click on save. And then click on this other one and change this from from sales to finance. Click on save. Another word discovering the tag, we go to the search box here at the top. Type in tag. It will show us a tags section under services here, you click on that. It will show us a list of all of our tags. And then if we click on the tag itself, it will show us all of the resource is under that tag. I've been tagged, though, that test VM 02 there. If we go into it, we've got test VM 01. Another way of doing this, if we go to. More resources. Well notice that we've got a lot of resources here against. Test VM 01, only one of them is tagged. So if we select all of these resources against test VM 01. We can go to assign tags at the top. Click on the tag that we went to sign so building. And Company, one and click a sign at the bottom. Now, after a couple of seconds all of those resources will be assigned with that tag. There we go back up the search box click on tags. Find company one. We'll see that all those resources are allocated under company one. Now, another way of applying tags and looking at tags this in powershell of course. So the first thing we need to do is to import the Azure. RM module if you haven't done already and connect to your Azure account. So, in order to get tags. We use the command get Azure RM tag. We run this line here. We'll see that it lists out all of the tags. And the values against them. That we currently allocated, however, if we want to search for VMs with the tag say company one against them. We run that it will show this sure enough test VM 01. Is allocated against company one? So notice to tag a VM. In powershell. First thing we need to do is get the details of the Azure. RM VM so. Will do that and put that into a variable called VM? If we look at that variable. Got all the details of the virtual machine here and it will show us that this test VM 03. There's no tag against it. So, in order to apply. A tag we need to use the set Azure. RM Resource Commandlet and feed it all. The details of the VM either resource group name. The resource type. The resource name and use that slash tag switched at the end and add a hash table with tag and the value that we want to add. But if we run this will see but it should add billing company 3 against this virtual machine to a week about things your console and select how virtual machines. Going to Demo 3. And tags. We'll see that it's got billing company 3 tagged against it. However, if we want to take all the resources allocated against the virtual machine, so the disk and the public IP address etc. We need to use get Azure. RM resource with that resource name and that VM name. And pipe that into set as your RM resource as we did before. However, in this example, we're applying 2 tags the company. And the Department so we run this. So if we go back to your console. Go into all resources. And search for test VM 03. Will say that all of these resources? I've got the company of techsnips dot IO and Department of training against them or another way to prove that is to go to the tags section. Click on the techsnipts Dot IO company tag. When you see all those resources. However, the downside of this command is that it overwrites all of the tags against the virtual machine. But even if it had 20 or 30 tags against it. You would overwrite it with these 2 and all the others would be deleted so in order to add tags. We need to gather the resource details into a variable called resource. We run that. Use the at syntax here in order to add the tag to that resource. And then use set Azure RM resource in order to set that tag against the machine. And if we get back to Azure console again. We should see that under our virtual machine. Test VM 03. We now have all the existing tags that it had like company techsnips dot IO us has the status of approved against it. And that was a short introduction in how to use tags in Azure.