0 Comments

If you’re developing an Azure based application, chances are you make frequent visits to the Azure portal. Now hopefully you don’t use it exclusively – at the very least your deployment should be automated (ideally with ARM templates) so you have a reliable and repeatable way to provision your application.

However, if you’re like me, you often find yourself needing to dive into the portal to check the status or configuration value of some resource or other. And if you have a lot of resources in your subscription(s) it can take a lot of clicking around, changing subscription, and filtering by resource type and group before you find the information you’re after.

This is where the Azure CLI can really help you out.

This week I kept needing to RDP into some virtual machines. So I needed to get the public IP address, the port numbers from a load balancer, and the password from a key vault secret. After manually doing this a few times, it dawned on me that the Azure CLI would be ideal to automate this.

To get the public IP address, I just needed to use the az network public-ip show command, and query for just the ipAddress property with a simple --query parameter. For commands like this returning a single value, I use the tab separated output option, as there is no need for it to be formatted as JSON.

az network public-ip show -n mypublicip -g myresourcegroup --query ipAddress -o tsv

Getting the value of the secret from the keyvault is just as simple. It’s az keyvault secret show, and asking for the value property:

az keyvault secret show --vault-name mykeyvault --name mysecret --query value -o tsv

The only slightly tricky command was asking the load-balancer for the port values. The inboundNatRules property of the output from az network lb show is a JSON array, and I wanted to pick out just the frontendPort properties from each object in that array. The JMESPath syntax for that is inboundNatRules[].frontendPort. And with the tsv output option, I’ll get each port number on a separate line:

az network lb show -n myloadbalancer -g myresourcegroup --query "inboundNatRules[].frontendPort" -o tsv

And so with three simple Azure CLI commands, I’ve automated the task of getting the RDP connection settings from the portal. It may not seem like a big deal, but the time saved by automating these simple repetitive tasks can add up over time.

What task do you keep visiting the Azure portal for that you could automate?

Vote on HN
comments powered by Disqus