Dela via


Updating Azure SQL Managed Instance properties using ARM templates

Azure SQL Managed Instance is fully managed SQL Server Database Engine hosted in Azure cloud. Azure SQL Managed Instance allows you to easily change instance settings such as changing number of cores assigned to the instance, adding more storage, etc. In this post you will see how easily you can automate these operations using ARM templates.

Preparing ARM request

Azure SQL Managed Instance can be configured using ARM templates that enable you to specify Managed Instance settings as set of properties in JSON format. You can submit these properties and deploy a new Managed Instance with the specified properties in Azure cloud.

You can also use these templates to update the properties of the existing instance. You should create the following JSON definition and save it as a local file:

 {
    "$schema": "https://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "resources": [
        {
            "name": "myinstancename",
            "location": "westcentralus",
            "type": "Microsoft.Sql/managedInstances",
            "properties": {
        /*  put the properties that should be updated here  */
            },
            "apiVersion": "2015-05-01-preview"
        }
    ]
}

You should put the properties that you want to change in the properties object. An examples of properties that can be used to change the storage size and the number of cores in the instance is shown here:

 "properties": {
    "storageSizeInGB": "512",
    "vCores": "8"
}

You can also change tags assigned to the instance, instead of properties - see definition of ARM template here. Note that you cannot change SKU(for example, change the generation) and VNET where the instance is placed.

Once you prepare JSON definition, you can submit the deployment request to Azure.

Submitting deployment requests

You need to have PowerShell libraries to submit ARM request to Azure. In order to execute ARM request, you would need to install Azure RM PowerShell. In most of the cases the following three commands might install everything that you need:

 Install-Module PowerShellGet -Force
Install-Module -Name AzureRM -AllowClobber

Then, you need to run something like the following PowerShell script :

 Connect-AzureRmAccount

Select-AzureRmSubscription -Subscription "{put-subscription-id-here}"

New-AzureRmResourceGroupDeployment `
               -ResourceGroupName {put_your_resource_group_here} `
               -TemplateFile 'c:\temp\miupdate.json'

In this script you need to put your subscription and the resource group where you want to deploy changes. This script will ask you to connect to your Azure account and deploy the changes defined in c:\temp\miupdate.json into your resource group. The only parameter needed in this command is existing resource group where you want to deploy the changes.