- Lab
- Cloud
- Data

Provision an Azure SQL Managed Instance Using Bicep
In this lab, you’ll build Bicep templates to deploy an Azure SQL Managed Instance in a secure Virtual Network, configure private endpoints for limited access, and apply best practices such as parameterization, modularization, and monitoring.

Path Info
Table of Contents
-
Challenge
Introduction and Setup
What are Bicep Templates?
Bicep is a domain-specific language (DSL) used for deploying Azure resources. It provides a declarative syntax for defining your infrastructure as code (IaC), which is then transpiled into Azure Resource Manager (ARM) templates.
A Bicep file is a human-readable file with the
.bicep
extension that describes the Azure resources you want to deploy and manage. It simplifies the process of defining Azure resources by abstracting the complexities of JSON-based ARM templates.Core Benefits of Bicep Templates
-
Simplified Syntax
- Bicep uses a clean, concise syntax that significantly reduces boilerplate code.
- Easier to read, write, and maintain compared to JSON-based ARM templates.
Example:
- ARM template:
{ "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2022-09-01", "name": "[parameters('storageAccountName')]", "location": "[resourceGroup().location]", "sku": { "name": "[parameters('skuName')]" } }
- Bicep equivalent:
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = { name: storageAccountName location: resourceGroup().location sku: { name: skuName } }
-
Modular and Reusable
- You can create reusable modules for common configurations, promoting code reusability.
- Modules allow you to organize and structure your code better by splitting large configurations into smaller, manageable parts.
-
Parameterization
- Supports parameterization, enabling the creation of flexible templates that can accept values at runtime, making templates reusable across environments (e.g., development, staging, production). ### Steps to Set Up Bicep
-
Ensure Prerequisites
- Azure CLI or Azure PowerShell are the command line tools that can be used to run and deploy your bicep templates to Azure.
-
Bicep CLI
- A command-line tool that helps you work with Bicep files, enabling you to define, validate, and deploy Azure infrastructure as code.
-
Log in to Azure
- Authenticate your CLI to your Azure account:
az login
- Authenticate your CLI to your Azure account:
info> Note: This environment does not have internet access so you don't need to run these installations. This lab will help you practice writing Bicep templates.
If you get stuck on a task, you can check thesolutions
folder. -
-
Challenge
Deploying a Basic Azure SQL Managed Instance
Like any Azure resource, Azure SQL Managed Instance can be deployed using Bicep templates, which would be beneficial for automation and version control.
Required Properties in Azure SQL Managed Instance Bicep Template
There are a few properties that must be defined in the bicep template for Azure SQL Managed Instance so that the deployment is successful:
- Name
- Location
- Administrator credentials
- Subnet with delegations for managed instances service and also includes a network security group and route table.
First, add the resource for Azure SQL Managed Instance with it's internal properties in the following task.
-
Challenge
Securing the Deployment with Virtual Networks
In order to be able to deploy Azure SQL Managed Instance successfully, there are specific network resources that should be added in the bicep template and linked to the Managed Instance's resource.
Network Resources
The network resources include:
- Virtual network
- Network security group that includes an allow outbound rule for the managed instances
- Route table
- Subnet with delegations configured for managed instances service
After adding all required resources in the template, it is now ready to be deployed to Azure.
This can be done by first, creating a resource group with Azure CLI:
az group create --name MyResourceGroup --location eastus2
Second, run the deployment command withing the resource group and using the template file as in the code below:
az deployment group create --resource-group MyResourceGroup --template-file main.bicep
info> Note: Since there is no internet access in this environment, you can not run the above deployment commands in this lab. These steps are included to keep in mind when using your local environment.
-
Challenge
Adding a Private Endpoint for Isolation
A Private Endpoint provides secure, private connectivity to an Azure SQL Managed Instance over a Virtual Network (VNet), ensuring that communication between clients and the database remains isolated from the public internet.
The private endpoint ensures that the Managed Instance is securely accessible only from within the private network, aligning with compliance and security requirements while simplifying infrastructure management.
Azure SQL Managed Instance provides a default VNet-local endpoint that operates as if the service was physically connected to your virtual network. For enhanced isolation and security, you can create private endpoints and link them to the managed instance. To learn what a private endpoint looks like, you can explore the
bicep-templates/privateEndpoint.bicep
file, which includes the definition of a private endpoint and the parameters that would include virtual network details and the name of the managed instance. -
Challenge
Modularizing the Template for Reusability and Best Practices
The current
bicep-templates/main.bicep
template defines all resources in a single file. However, it is recommended to break the deployment into smaller modules for better maintainability and to include their IDs as output fields at the end of each module. ### Putting It All Together
You have gained hands-on experience provisioning Azure SQL Managed Instances using bicep. You’ve explored key tasks like configuring networking, deploying resources, setting up secure access, and enabling monitoring—all through the Insfrastructure as Code setup along with best practices for maintainable templates and resources.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.