While using pipelines in DevOps to deploy applications is the most common scenario for automated deployment, there is also automated deployment of infrastructure resources. Especially after adopting cloud computing platforms, combining infrastructure-as-code approaches can more conveniently integrate cloud resource management into DevOps pipelines, achieving overall automated deployment from resources to applications using DevOps. Today, using Azure cloud as an example, we introduce a basic automated cloud resource management solution.
Preparing ARM Templates
Azure Resource Manager (ARM) templates are JavaScript Object Notation (JSON) files that define the deployment of Azure solutions. These templates define the resources of a solution and the properties for deploying those resources. ARM templates follow a declarative syntax where you specify what you want to deploy without writing the sequence of commands for the deployment.
Verifying Azure AD User Permissions
Before starting, ensure your Azure AD user has appropriate permissions to deploy resources. Usually the following permissions are required: - "Contributor" role or higher permissions on the target resource group - Permissions to create and manage Azure resources - Access permissions to the Azure DevOps project
Configuring Azure DevOps Release Pipeline
Creating Azure DevOps Service Connection
In Azure DevOps, service connections allow you to connect external services to Azure DevOps. To deploy to Azure, you need to create an Azure Resource Manager service connection.
- In the Azure DevOps project, navigate to "Project Settings"
- Select "Service connections"
- Click "New service connection"
- Select "Azure Resource Manager"
- Choose the appropriate authentication method (service principal is usually recommended)
- Fill in subscription details and complete the configuration
Creating Release Pipeline
- In Azure DevOps, navigate to "Pipelines" -> "Releases"
- Click "New pipeline" to create a new pipeline
- Select "Empty job" template
- Add a "Stage" and name it "Deploy to Azure"
- Add an "Azure Resource Group Deployment" task in the Stage
- Configure task parameters: - Select the service connection created earlier - Specify the target resource group - Select deployment mode (incremental or complete) - Specify ARM template file path - If needed, specify parameter file path
ARM Template Best Practices
- Use parameterized templates to make templates reusable
- Use clear naming conventions for parameters and variables
- Use nested templates for complex deployments
- Include resource dependencies in templates
- Use conditional deployment to control resource creation
- Validate templates to ensure correctness
Summary
By combining ARM templates with Azure DevOps pipelines, automated deployment and management of infrastructure can be achieved. This approach provides a repeatable, reliable, and auditable deployment process, which is an essential part of modern cloud-native application development. As organizations' demand for automation grows, this infrastructure-as-code approach will become increasingly important.