Configure an Azure Automation Account - Part 2 - Credentials and Variables
This is part two of a three part series to get you up and running with Azure Automation. The end goal is the execution of an Azure Automation run book.
Here's a reminder of the process and the posts.
- Create a new user in the Azure Active Directory associated with your subscription (this becomes the Automation Credential)
- Assign the user as co-administrator in the subscription
- Create an Azure Automation Account
- Add an Azure Automation Credential
- Add an Azure Automation Variable
- Create a run book that uses the components from posts one and two
- Test the run book
To be able to execute code in an Azure Automation run book, you'll need a credential. We created a suitable account in post one and now we need to make it available to a run book.
Add an Azure Automation Credential
In part one, we created an Azure Automation Account called 'TheBigBadWolf'. We also created a user called 'Anne Droid', a co-administrator of the Azure subscription. Let's bring the two together.
$cred = Get-Credential -UserName "AnneDroid@ninja-injury.com" -Message "Azure Automation Credential"
New-AzureAutomationCredential -AutomationAccountName "TheBigBadWolf" -Name "AzureWolfCredential" -Description "Automation Credential for TheBigBadWolf" -Value $cred
NB - it's worth noting that you may need to use Add-AzureAccount to log back in prior to running New-AzureAutomationCredential... post one was a week ago, after all!
We now have a credential associated to an automation account in the subscription. It also has the necessary permissions to execute run book code... but how do we identify the subscription to the run book? Read on.
Add an Azure Automation Variable
New-AzureAutomationVariable -Name "WolfSubscriptionId" -Description "Automation Variable for TheBigBadWolf" -Value "d2d4814c-cb9d-4849-8990-88fc7e7cade2" -Encrypted $false -AutomationAccountName "TheBigBadWolf"
Easy. We now have the foundation components to execute a run book in Azure: an execution credential and a variable that references the subscription.
Next time out we'll create, test and schedule a run book.