Image Reference: Template design
Here are a few benefits of using the ARM templates.
- Declarative syntax: You can define multiple Azure services such as VM, database, networks in a single deployment template
- Repeatable results: The ARM templates can be used multiple times so that you can deploy Azure infrastructure repeatedly with consistency
- Orchestration: Once we define multiple infrastructure pieces in the script, the resource manager orchestrates deploying resources correctly. It also starts their parallel deployment so that you can running infrastructure ASAP
- Built-in validation: Once you submit the ARM templates, the resource manager goes through a validation check. If the validation is successful, it starts resource deployment. Therefore, it has lesser chances of stopping deployment in a half-finished state
- Export templates: The Azure portal allows the export of the automation script and deploys it as an ARM template. Therefore, if you do not know JSON or ARM templates, you can still use them
- Continuous integration and deployment: You can integrate the templates in the CI/CD tools such as Azure DevOps for fast, reliable infrastructure deployments
Template file section
The ARM template has the following sections:
- Parameters: The parameters allow users to specify different values during the deployment of ARM templates
- Variables: The variables enable users to specify different values during deployment to re-use the templates
- User-defined functions: You can deploy custom functions for simplifying template deployment
- Resources: These define Azure resources for deployment
- Outputs: We can specify the output format from the deployed resources
- Note: You can refer to the Microsoft documentation for detailed information on Azure Resource Manager templates
Deploy Azure Container Instance(ACI) using ARM templates
Azure Container Instance is a managed service for running container instances with deployed images into Azure. You can use persisted or non-persisted(storage) for the container. The container deployment enables developers to deploy their code without waiting for infrastructure (VM, Servers) and installing databases. In the articles( TOC at the bottom), we explored deploying containers using the following ways with the SQL Server 2019 Linux image.
- Azure Portal
- Azure CLI
- Use persisted storage for storing database files independently of the ACI lifecycle
This article explores deploying the Azure Container Instance for SQL Server On Linux using ARM templates. The quickest method to get the template script is to fill the ACI in the Azure portal initially. You can follow the article, Azure Container Instances for SQL Server 2019, to understand various container deployment options.
On the review page, you get an option – Download a template for automation.
Click on the option, and it generates a template with the JSON script.
In the template menu, you get multiple options, as outlined below.
Visualize template: The visualize templates show the resources graphically you will deploy using this ARM template. For example, it shows below the ACI graphically
- Download: You can download the JSON script for review and modification
- Add to the library (preview): You can directly add this template into the Azure library to refer it for later deployments
Let’s download and extract the compressed files. It includes a parameter and template JSON script file.
Let’s open the files in the VS Code editor.
This parameter file contains the input we provided during the Azure Container Instance ACI configuration. For example, Container name, image type, location, CPU cores, memory, restart policy, port number, environment variables.
The environment variable 1 belongs to the MSSQL SA password. It shows value as NULL because we used the secured string to hide the password in the script.
The template JSON script file has two sections.
Parameter section with their types
Each parameter is defined with a type. For example, the location is a string type
Azure resource details
In this section, the template defines the type of Azure resource and their details for configuration. For example, the ACIs has the following value –
As you can see, the ACCEPT_EULA and MSSQL SA password values are from the specified environment variable parameter.
Deploy ARM template for Azure Container Instance using default templates
You can also use the ACI template samples stored in the GitHub library.
We can use the Azure Container Instances – Linux container with public IP to deploy a single Linux container.
Click on Deploy to Azure, and you get the following page.
However, this template does not have options for SQL Server configurations such as environment variables for SA password and EULA. Therefore, you can click on the edit template to add the relevant details.
Here, I replace the content of the template and parameters with the script file downloaded earlier. Once modified, save both template and parameter files.
The updated Azure container instance deployment page looks as below. It displays all parameters and their values on this page.
You can modify the values if required. If you specify any explicit values here, it overrides the parameters’ values specified in the parameter.json. For example, I modified the container name as azuresqlcontainer1. Click on Review + Create so that the Azure resource manager can validate the Azure template for container deployment.
As shown below, the validation is successful from a customized template.
Click on Create. It starts deployment based on template inputs.
Once the deployment completes, you can view your resources. As shown below, we have the container name as [azuresqlcontainer1], the name defined earlier.
Now, you can connect to SQL Server using the public IP address or DNS name for writing your DB queries.
Deploy ARM templates using Azure CLI
We learned to deploy the Azure Container Instance with SQL Server 2019 Linux image with the Azure Resource Manager (ARM) templates. However, we used the Azure portal for deploying resources with the template.
The benefit of templates is that you can deploy them using the Azure command-line interface(CLI). Therefore, once you have defined templates, you can store them in Azure library, Repositories such as GitHub, or local directory. You can modify the parameter’s value in the parameter file or specify values explicitly to override default values. In this article, we will use the template files downloaded earlier and stored in the local directory.
The Azure CLI script uses az deployment group create for ARM resource deployment. In the following script, we specify the path of both parameter and template JSON files using parameters $parameterfile and $templatefile.
Later, the script reference them using the parameters template-file and parameters as shown below.
Before running the script, run az login and authenticate to Azure using your credentials in the Windows PowerShell or terminal bash.
It starts deploying Azure resources after reading the values from both template and parameter files of ARM templates. Wait for few minutes while the script output is Running.
It returns container JSON metadata once resources are deployed successfully.
You can log in to the Azure portal for verification of container resources.
You can now quickly deploy resources without navigating the Azure portal, filling configuration values. For example, I modified parameters values and executed them using CLI for another Azure Container Instance.
As shown below, we have two Azure Container instance running with SQL Server 2019 Linux image.
This article explored the automation process to deploy Azure Container Instances with SQL Server Linux images using ARM templates. The ARM templates can make life easier with quick deployment and minimal manual intervention of the Azure portal for individual service deployment.
- Deploying Azure Container Instances using YAML - January 21, 2022
- Use ARM templates to deploy Azure container instances with SQL Server Linux images - December 21, 2021
- Remote desktop access for AWS RDS SQL Server with Amazon RDS Custom - December 14, 2021