Objective: To show my own experience and development workflow for building out infrastructure-as-code with Azure Resource Manager (ARM) Templates. My hope is that for novices this provides some insight and starting point to develop your own workflow.
My Infrastructure as code workflow:
1. Setup a development azure subscription and resource group for your ARM deployment. Ensure you have at least Contributor permissions. Install software tools. See this blog post detailing the software tools I prefer to use.
2. Usually, I start off manually creating the Azure resources in the Azure Portal to familiarize myself with the configuration settings, any related security service principals and how these resources depend on one another as an overall solution. For example, a solution with App service plan, web app, key vault and Azure SQL Server Azure SQL DB.
3. Develop the ARM templates.
I usually start off with examples from the azure quickstart templates
Or I sometimes use the VS Code extension ARM tool and generate ARM snippets.
And then generating a boiler plate arm snippet
Another method is manually provisioning your azure resources in the Azure Portal. Then Export template. The more complex the exported arm template, the more cleanup and refactoring you have to do to shape the ARM template that way you like so that it is maintainable. Because of this, I find it harder to start with the ‘Export template’ approach.
4. Validate ARM Template with Azure PowerShell using cmdlet Test-AzResourceGroupDeployment
Test-AzResourceGroupDeployment -ResourceGroupName <groupNmae> -TemplateUri <template> -TemplateParameterUri <paramaters>
This doesn’t validate or test the deployment but rather validates the syntax.
5. Deploy ARM template with Azure PowerShell cmdlet New-AzResourceGroupDeployment
New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateFile <path-to-template>
Then go to the resource group in the Azure Portal. Click on the Deployments blade to see the deployments and progress. Here we see the deployment of multiple ARM templates linked together via a main ARM Template. Notice that two ARM template deployments can go in parallel to speed up the deployment.
6. Troubleshoot errors
If a deployment fails, you can click into the deployment details to see the error details
Research and fix the issue based on the error message. Update your ARM template
8. Git Commit and Push to public Github repo or a private repo in Azure DevOps Repo
9. Repeat step 2. as needed
Develop Azure DevOps Pipeline to have automated deployments
The following is a simple Release pipeline.
- Arm templates stored in a Github repo
- Trigger based on a commit into the main branch
- Deploy ARM template to a dev environment targeting a specific resource group
- Deploy ARM template to a prod environment targeting a specific resource group
I plan to do a deeper dive on the Azure Pipeline, but for now I like to show a high level example of mine.
I have shared my own development workflow so that it may be a reference model for those figuring out theirs.
- Deploy resources with Resource Manager templates and Azure PowerShell
- Integrate Resource Manager templates with Azure Pipelines
- My blog post: ARM Template Fundamentals: My Development Tools