| title | Quickstart: Create Instance with Terraform | |
|---|---|---|
| description | Learn how to create and deploy Azure SQL Managed Instance with Terraform | |
| author | vladai78 | |
| ms.author | vladiv | |
| ms.reviewer | mathoma | |
| ms.date | 08/26/2025 | |
| ms.service | azure-sql-managed-instance | |
| ms.topic | quickstart | |
| ms.custom |
|
Article tested with the following Terraform and Terraform provider versions:
This article shows how use Terraform to deploy an Azure SQL Managed Instance in a virtual network and a subnet associated with a route table and a network security group.
[!INCLUDE Terraform abstract]
In this article, you learn how to:
[!div class="checklist"]
- Create all supporting services for SQL Managed Instance to run on
- Deploy SQL Managed Instance
Note
The example code in this article is located in the Azure Terraform GitHub repo. See more articles and sample code showing how to use Terraform to manage Azure resources
[!INCLUDE open-source-devops-prereqs-azure-subscription.md]
- In the general case, your user needs to have the role SQL Managed Instance Contributor assigned at subscription scope.
- If provisioning in a subnet that is already delegated to Azure SQL Managed Instance, your user only needs the Microsoft.Sql/managedInstances/write permission assigned at subscription scope.
- Install and configure Terraform
-
Create a directory in which to test and run the sample Terraform code and make it the current directory.
-
Create a file named
providers.tfand insert the following code: [!code-terraformmaster] -
Create a file named
main.tfand insert the following code: [!code-terraformmaster] -
Create a file named
variables.tfand insert the following code: [!code-terraformmaster]
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
To verify the results within the Azure portal, browse to the new resource group. The new instance will be in the new resource group after it's deployed. To see the deployment progress keep your PowerShell open or navigate to the Azure portal, search for SQL Managed Instance and then filter all instances by status.
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Learn more about Azure SQL Managed Instance