Azure Automation is one of the powerful features that Microsoft provides, that allows users to either write fresh scripts or leverage existing PowerShell scripts, and execute them through the Azure Portal.
My intention with this blog is to give you an idea of what Azure Automation is capable of, and start thinking how you could leverage this product within your own Azure infrastructure. As I prefer to explain technology via a demonstration, I thought I'd run through some examples with a few screenshots. If you'd like to have a read of the official Microsoft documentation beforehand, read here.
In this demo, I'll demonstrate how to create a Runbook and write a simple script that connects to Azure and gets subscriptions and resources.
First of all, navigate to the Azure Automation page and create an account. I called this one "TestAutomationAccount".
Once created, click Runbooks and then Add a runbook.
Fill in the name, select the Runbook type as 'PowerShell Workflow' and click Create. You can add a description, but that's optional.
Once created, you will then be redirected to the Edit page, which looks very similar to typical program editors.
On the left-hand side, there are CMDLETS/RUNBOOKS/ASSETS panels that provide the list of available commandlets that Azure Automation provides. You can expand them to pull out further details.
To connect to Azure with PowerShell, a credential PSObject is required. The object could be created within the script by using a plain text password, but security-wise, it's best to encrypt. Hence, I will be creating a credential asset to store an encrypted password. From the Settings menu, click on Assets.
Then click Credentials, Add a credential, and fill in the name of the Asset, Username, and Password (make sure this user has admin access to at least one subscription). In this case I called it "AzureAccount".
Once the asset credential is created, go back to the Runbook Edit window. Then, expand Assets, Credentials, and you will see the "AzureAccount" credential created. If you aren't sure how to use the asset, simply right-click and add to canvas. It will automatically populate a line for you.
Using the credential above, finish off the script. An example script is shown below.
Save the Runbook and navigate to the Test Pane. This is where you can test out your script just like local PowerShell. Click Start and you will see that it connects to Azure and prints out available subscriptions and ARM resources.
From here on, you can start building your own Runbook.
Why would you do Azure Automation?
Using Azure Automation provides a number of ways to reduce cost. First of all, you'll be reducing human cost. For instance, there will be certain tasks that Ops teams need to perform for the Dev team. With Azure Automation, you can simply give access to the Dev team to execute Runbooks themselves; freeing up Ops to concentrate on other tasks.
Another example is that infrastructure costs can be reduced. For example, if you live in New Zealand and workloads are globally dispersed, you will definitely need at least one medium-to-high spec virtual machine in each region in order to manage workloads, such as upgrading a database with DACPAC. Instead of utilising virtual machines, you can convert them into Runbooks. The cost of running a Runbook is $0.003/min in NZD. This is definitely much cheaper than running virtual machines.
Azure Automation provides Github integration that provides access control and collaboration features. Repositories can be maintained by both the Dev and the ops teams to develop codes efficiently.
Unfortunately, Visual Studio Online (TFS) is not supported at the time of writing this blog.
Not only can a Runbook be scheduled, but it can also be triggered by an Azure Alert. One of the best outcomes we're delivering for our customers is to run a set of SQL performance queries when a high DTU utilisation is triggered. The Runbook collects the necessary data and sends the report to the Ops/Dev team for investigation. With this approach, troubleshooting has become much easier as real-time data can be gathered.
More details around Webhook can be found here.
Give it a go
There are a lot of other Azure Automation features available, such as Desired State Configuration (DSC), developing your own Modules, hybrid setup, and so on. Certainly, this is the best way to optimise and automate your current Azure infrastructure.
If you're interested, reach out to us to learn more about other customer use cases.