Guide
- Create a free Azure DevOps Account
- Create a Repository
- Create an ARM Template
- Configure Service Connection to Azure Subscription
- Deploy ARM Template to Azure
- Configure Continuous Deployment
Create a free Azure DevOps Account
Navigate to https://azure.microsoft.com/en-us/services/devops/ and sign up for a free account.
Create Repository
If you don’t have one already, create an empty project. After opening your project, click Repos on the left navigation section.
Click New Repository.
Be sure to choose the ignore file for the application you are writing code in. I chose Visual Studio, as I use either Visual Studio or VS Code. Click Clone, then click “Clone in VS Code”.
Choose the folder where you want to store your source code.
Great! Now we have an Azure DevOps account, project, repository, and have it cloned in VS Code! In the next step we can start working in VS Code.
Create an ARM Template
First, be sure to install the Azure Resource Manager (ARM) Tools extension. You can do this in VS Code by clicking the extension button.
Click on the file icon from your toolbar, and create a new file. I called mine coreSA.json.
Next, locate at the bottom right of your screen “JSON” and click it. From the drop down menu, choose Azure Resource Manager Template.
While your cursor is in the body, start typing arm and notice the options that appear. Press tab to have IntelliSense complete the code for arm!.
Place your cursor between the resources square brackets [ ] and make an empty line. Then type arm-storage and use the IntelliSense to auto fill. Name your storage account name and displayName.
Save the file and click the branch icon from the toolbar on the left. Type a meaningful message for change tracking and press CTRL+Enter to commit the change.
You will now notice at the bottom left of your screen you will see a counter that just incremented to 1 with an arrow up next to it. Click the icon to synchronize the update to the Azure DevOps repository.
Jump back to your browser to our Azure DevOps project and click Files from the menu on the left. You should now see your new file created.
There we have it, an ARM template. Next, we will configure Azure DevOps to deploy this template for us.
Configure Service Connection to Azure Subscription
First off, you will need an Azure subscription. You can sign up for a free trial or use a credit card.
From Azure DevOps, locate the Project Settings cog wheel on the bottom left of your screen and click it. Scroll down to the bottom and click Service connections, not to be confused with Service hooks located higher in the menu.
Click the button to create a new service connection and choose Azure Resource Manager and click Next. Choose Service principal (this is an interesting step and Microsoft is automatically creating an identity for you in the background. I recommend you research these different solutions for production use.)
For scope level, I will choose Subscription — again, for production use you will want to determine on your own which level is appropriate. You will likely get prompted for authentication to your subscription.
Click Save.
Hopefully your service connection now shows on the page and you are ready for the next step of creating the storage account!
Deploy ARM Template to Azure
For the purposes of this article, we will manually create the resource group that needs to be deployed. Do this now. In a separate article I will explain how to automate the deployments of the resource groups.
From the toolbar in Azure DevOps, click Releases from the space shuttle icon.
Click the New pipeline button and choose Empty job.
Click Add an artifact. Click the Azure Repo icon and select the values to locate the repository you have been working with. Take special notice to the Source alias field — this will be used later.
Click Add, then click the hyperlink on the Stage 1 box.
Click the + icon on the Agent job row. Search for Azure resource group and add it to the stage.
Fill out the required fields and be sure to choose Linked artifact for the Template location. Click the ellipsis to navigate to the template file. Notice the source alias matches our artifact source alias we noted earlier.
Rename the pipeline to something more meaningful at the top of the page. I changed mine to Deploy to Azure. Click Save, then click Create release.
Type a release description and click Create!
You will see a hyperlink appear to view the status of the release. Click the link. Click the Logs button under the In Progress window.
If all goes well, you will see a successful result! Now you can check your resource group in Azure to confirm that the storage account was created.
If you’ve made it this far, keep going to the last step, and my favorite part — setting up continuous deployment to deploy to Azure every time the repository is updated!
Configure Continuous Deployment
From the releases area, highlight your release pipeline and click Edit from the top right of Azure DevOps.
Click the Lightning bolt icon on your artifact. Toggle the switch for Continuous deployment trigger for your Git repository. Click Save.
Go back to your ARM template and change the name of the storage account that was created. Go back to Azure DevOps and notice that the release has automatically been triggered!
That’s it!
Conclusion
This is a very basic example of how to deploy a resource to a resource group in Azure. You will quickly realize that this will not satisfy an actual business requirement because you will likely need to use variables, parameters, deploy to multiple resource groups, etc. I will cover all of this in a future article when I talk about using linked templates and using Azure CLI to trigger the ARM templates being executed!
