Creating VM's from image and adding to an existing Availability Set - azure

How can I add an existing VM that I either created in the portal or imported from vmdepot to an existing availability set? It doesn't seem to be possible from the portal, does it work in Powershell? Does it work at all with the Resource Manager deployment model?

Currently, for ARM Deployment, Setting Availability set is not supported yet. Availability set could only be added during creation. Hence, for your case, you need to delete the current instance, and create a new deployment with the old OSDisk, Vnet, and some other setting.
This can be achieved by using ARM Template. The following example shows you how to deploy a VM with an existing VHD and Vnet. It also create a new availability set, and add the VM to the availability set.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"metadata": {
"description": "Please enter the location where you want to deploy this VM"
}
},
"vmName": {
"type": "string",
"metadata": {
"description": "Name of the VM"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"metadata": {
"description": "Type of OS on the existing vhd"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the existing VHD in ARM standard or premium storage"
}
},
"vmSize": {
"type": "string",
"metadata": {
"description": "Size of the VM"
}
},
"existingVirtualNetworkName": {
"type": "string",
"metadata": {
"description": "Name of the existing VNET"
}
},
"existingVirtualNetworkResourceGroup": {
"type": "string",
"metadata": {
"description": "Name of the existing VNET resource group"
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "Name of the subnet in the virtual network you want to use"
}
},
"dnsNameForPublicIP": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"availabilitySetName": {
"type": "string",
"metadata": {
"description": "The name of your Availability Set."
}
}
},
"variables": {
"api-version": "2015-06-15",
"publicIPAddressType": "Dynamic",
"vnetID": "[resourceId(parameters('existingVirtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]",
"nicName": "[parameters('vmName')]",
"publicIPAddressName": "[parameters('vmName')]"
},
"resources": [
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "PublicIPAddress"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForPublicIP')]"
}
}
},
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
],
"tags": {
"displayName": "NetworkInterface"
},
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[parameters('availabilitySetName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"platformFaultDomainCount": "3",
"platformUpdateDomainCount": "20"
}
},
{
"apiVersion": "[variables('api-version')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"AvailabilitySet" : {
"id": "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]"
},
"storageProfile": {
"osDisk": {
"name": "[concat(parameters('vmName'))]",
"osType": "[parameters('osType')]",
"caching": "ReadWrite",
"vhd": {
"uri": "[parameters('osDiskVhdUri')]"
},
"createOption": "Attach"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
}
}
}
]
}
If you want to add the VM to an existing availability set, you can delete
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[parameters('availabilitySetName')]",
"apiVersion": "2015-06-15",
"location": "[parameters('location')]",
"properties": {
"platformFaultDomainCount": "3",
"platformUpdateDomainCount": "20"
}
},
and
"[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]",
For more details about authoring ARM template, see Authoring Azure Resource Manager templates
For more information about how to deploy an ARM template, see Deploy a Resource Group with Azure Resource Manager template
And the above template is modified from this sample template from GitHub.
After I posted this answer, I had been thinking about using REST API to update vm with an availability set. I thought it might work, so I gave it a shot, and here is the error message I got:
Invoke-RestMethod : {
"error": {
"code": "PropertyChangeNotAllowed",
"target": "availabilitySet.id",
"message": "Changing property 'availabilitySet.id' is not allowed."
}
}
At C:\Users\v-dazen\Documents\setVMRestAPI.ps1:13 char:1
+ Invoke-RestMethod -Method Put -Uri "https://management.azure.com/subs ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
That means setting the availability set for an existing ARM deployed VM is not possible yet.

Related

Azure resources created using custom provider not showing on azure portal

I created an Azure custom provider by following the documentation in the link below:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/custom-providers/
I am able to successfully create resources for the types defined in the custom provider using ARM templates. However, I do not see those resources on the azure portal under the specific resource group.
Is this behavior expected?
I have deployed the custom provider in azure portal using ARM template by following below steps
Open azure portal and search for custom deployment as below
Taken reference from Microsoft Doc
After opening custom deployment, i have used the below code and then click on save
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"funcName": {
"type": "string",
"defaultValue": "[uniqueString(resourceGroup().id)]",
"metadata": {
"description": "The unique name of the function application"
}
},
"storageName": {
"type": "string",
"defaultValue": "[concat('store', uniquestring(resourceGroup().id))]",
"metadata": {
"description": "The unique name of the storage account."
}
},
"location": {
"type": "string",
"defaultValue": "eastus",
"metadata": {
"description": "The location for the resources."
}
},
"zipFileBlobUri": {
"type": "string",
"defaultValue": "https://github.com/Azure/azure-docs-json-samples/blob/master/custom-providers/_artifacts/functionpackage.zip?raw=true",
"metadata": {
"description": "The URI to the uploaded function zip file"
}
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2022-03-01",
"name": "[parameters('funcName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
],
"properties": {
"name": "[parameters('funcName')]",
"siteConfig": {
"appSettings": [
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2022-05-01').keys[0].value)]"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2022-05-01').keys[0].value)]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2022-05-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[toLower(parameters('funcName'))]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "6.5.0"
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "[parameters('zipFileBlobUri')]"
}
]
},
"clientAffinityEnabled": false,
"reserved": false
}
},
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-05-01",
"name": "[parameters('storageName')]",
"location": "[parameters('location')]",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS"
}
},
{
"type": "Microsoft.CustomProviders/resourceProviders",
"apiVersion": "2018-09-01-preview",
"name": "[parameters('funcName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Web/sites/',parameters('funcName'))]"
],
"properties": {
"actions": [
{
"name": "ping",
"routingType": "Proxy",
"endpoint": "[concat('https://', parameters('funcName'), '.azurewebsites.net/api/{requestPath}')]"
}
],
"resourceTypes": [
{
"name": "users",
"routingType": "Proxy,Cache",
"endpoint": "[concat('https://', parameters('funcName'), '.azurewebsites.net/api/{requestPath}')]"
}
]
}
},
{
"type": "Microsoft.CustomProviders/resourceProviders/users",
"apiVersion": "2018-09-01-preview",
"name": "[concat(parameters('funcName'), '/ana')]",
"location": "parameters('location')",
"dependsOn": [
"[concat('Microsoft.CustomProviders/resourceProviders/',parameters('funcName'))]"
],
"properties": {
"FullName": "Ana Bowman",
"Location": "Moon"
}
}
],
"outputs": {
"principalId": {
"type": "string",
"value": "[reference(concat('Microsoft.Web/sites/', parameters('funcName')), '2022-03-01', 'Full').identity.principalId]"
}
}
}
Fill the following details like Subscription id, resource group, location and click on review+create
After deploying into the azure portal, we will get below
After deploying it to azure poral Goto azure portal and click on your resource group and click on the check box you will find as below

ARM Template for creating VM in azure using existing VHD Uri (osDiskVHDUri) & join to domain

Use-case description:
I've a use case wherein, we need to create a VM in azure using the existing VHD Uri available in storage account & the same ARM template should have the feasibility to join to domain. At the present currently tried working & executing the ARM template which has only flexibility of using the existing VHD Uri and creating a VM (this Uri will act as "OsDiskVhdUri") & another template has only the ability to create new VM and join to domain these are working on standalone basis.
Key highlighters:-
Need a template which has both "OsDiskVhdUri" & domain join parameters.
Template reference should be "OsDiskVhdUri", because when i tried integrating both templates & troubleshooting - Image reference related errors are there on while deployment.
The very important point, was - the ARM template while blueprint assignment asks for OsDiskVhdUri parameter and although I give the Uri for creating the VM, with the below template, it doesn't seems to take that Uri" instead it creates a NEW VM every time and attaches to domain.
Deployment method is blueprint in Azure.
Error:-
type 'Template' failed to deploy due to the following error: Template deployment failed with error [ { "message": "Could not find member 'osDiskVhdUri' on object of type 'ImageReference'. Path 'properties.storageProfile.imageReference.osDiskVhdUri', line 1, position 237." }
Exhausted all methods finding still deeper dive into it & any guidance on this will be highly appreciated!!
Code for reference:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"existingVNETName": {
"type": "string",
"metadata": {
"description": "Existing VNET that contains the domain controller"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the existing VHD in ARM standard or premium storage"
}
},
"osType": {
"type": "string",
"defaultValue": "2019-Datacenter",
"allowedValues": [
"2019-Datacenter"
],
"metadata": {
"description": "The Windows version for the VMs. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
}
},
"existingSubnetName": {
"type": "string",
"metadata": {
"description": "Existing subnet that contains the domain controller"
}
},
"vmname": {
"type": "string",
"metadata": {
"description": "Unique public DNS prefix for the deployment. The fqdn will look something like '<dnsname>.westus.cloudapp.azure.com'. Up to 62 chars, digits or dashes, lowercase, should start with a letter: must conform to '^[a-z][a-z0-9-]{1,61}[a-z0-9]$'."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2_v2",
"metadata": {
"description": "The size of the virtual machines"
}
},
"domainToJoin": {
"type": "string",
"metadata": {
"description": "The FQDN of the AD domain"
}
},
"domainUsername": {
"type": "string",
"metadata": {
"description": "Username of the account on the domain"
}
},
"domainPassword": {
"type": "string",
"metadata": {
"description": "Password of the account on the domain"
}
},
"ouPath": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU in quotation marks. Example: \"OU=testOU; DC=domain; DC=Domain; DC=com\""
}
},
"domainJoinOptions": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Set of bit flags that define the join options. Default value of 3 is a combination of NETSETUP_JOIN_DOMAIN (0x00000001) & NETSETUP_ACCT_CREATE (0x00000002) i.e. will join the domain and create the account on the domain. For more information see https://msdn.microsoft.com/en-us/library/aa392154(v=vs.85).aspx"
}
},
"vmAdminUsername": {
"type": "string",
"metadata": {
"description": "The name of the administrator of the new VM and the domain. Exclusion list: 'admin','administrator"
}
},
"vmAdminPassword": {
"type": "string",
"metadata": {
"description": "The password for the administrator account of the new VM and the domain"
}
},
"location": {
"type": "string",
"defaultValue": "East US",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[concat('diags', uniquestring(resourceGroup().id))]",
"diskName": "[concat('diags', uniquestring(resourceGroup().id))]",
"osDiskVhdUri": "[concat(parameters('osDiskVhdUri'), '-image')]",
"nicName": "[concat(parameters('vmname'),'Nic')]",
"publicIPName": "[concat(parameters('vmname'),'Pip')]",
"subnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', parameters('existingVNETName'), parameters('existingSubnetName'))]"
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('vmname')]"
}
}
},
{
"type": "Microsoft.Compute/disks",
"apiVersion": "2018-09-30",
"name": "[variables('diskName')]",
"location": "[parameters('location')]",
"properties": {
"creationData": {
"createOption": "Import",
"sourceUri": "[parameters('osDiskVhdUri')]"
}
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"properties": {
"accountType": "Standard_LRS"
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]"
},
"subnet": {
"id": "[variables('subnetId')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/images",
"apiVersion": "2020-06-01",
"name": "[variables('imageName')]",
"location": "[parameters('location')]",
"properties": {
"hyperVGeneration": "V2",
"storageProfile": {
"osDisk": {
"osType": "[parameters('osType')]",
"osState": "Generalized",
"blobUri": "[parameters('osDiskVhdUri')]",
"caching": "ReadWrite",
"storageAccountType": "Standard_LRS"
}
}
}
},
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[variables('nicName')]",
"[variables('imageName')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
}
}
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmname'),'/joindomain')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('vmname'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "JsonADDomainExtension",
"typeHandlerVersion": "1.3",
"autoUpgradeMinorVersion": true,
"settings": {
"Name": "[parameters('domainToJoin')]",
"OUPath": "[parameters('ouPath')]",
"User": "[concat(parameters('domainToJoin'), '\\', parameters('domainUsername'))]",
"Restart": "true",
"Options": "[parameters('domainJoinOptions')]"
},
"protectedSettings": {
"Password": "[parameters('domainPassword')]"
}
}
}
]
}
If you want to create Azure VM with vhd file, please update your template as below
{
"type": "Microsoft.Compute/images",
"apiVersion": "2020-06-01",
"name": "[variables('imageName')]",
"location": "[parameters('location')]",
"properties": {
"hyperVGeneration": "V2",
"storageProfile": {
"osDisk": {
"osType": "[parameters('osType')]",
"osState": "Generalized",
"blobUri": "[parameters('osDiskVhdUri')]",
"caching": "ReadWrite",
"storageAccountType": "Standard_LRS"
}
}
}
},
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[variables('nicName')]",
"[variables('imageName')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
}
}
}
}

ARM template for elastic database pool fails

I'm having issues trying to deploy an ARM with ElasticPool GeneralPurpose edition. ihave to tried this in mulitple environment but it keeps failing. I'm using the code below which referenced from the Github repository of starter templates
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"administratorLogin": {
"type": "string",
"metadata": {
"description": "The SQL Server administrator login"
}
},
"administratorLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The SQL Server administrator login password."
}
},
"serverName": {
"type": "string",
"metadata": {
"description": "The SQL Server name."
}
},
"elasticPoolName": {
"type": "string",
"metadata": {
"description": "The Elastic Pool name."
}
},
"edition": {
"type": "string",
"defaultValue": "Standard",
"allowedValues": [
"Basic",
"Standard",
"Premium",
"GP_Gen5",
"BC_Gen5"
],
"metadata": {
"description": "The Elastic Pool edition."
}
},
"capacity": {
"type": "int",
"metadata": {
"description": "The Elastic Pool DTU or nomber of vcore."
}
},
"databaseCapacityMin": {
"type": "int",
"defaultValue": 0,
"metadata": {
"description": "The Elastic Pool database capacity min."
}
},
"databaseCapacityMax": {
"type": "int",
"metadata": {
"description": "The Elastic Pool database capacity max."
}
},
"databasesNames": {
"type": "array",
"defaultValue": [
"db1",
"db2"
],
"metadata": {
"description": "The SQL Databases names."
}
},
"databaseCollation": {
"type": "string",
"defaultValue": "SQL_Latin1_General_CP1_CI_AS",
"metadata": {
"description": "The SQL Database collation."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"editionToSkuMap": {
"Basic": {
"family": null,
"name": "BasicPool",
"tier": "Basic"
},
"Standard": {
"family": null,
"name": "StandardPool",
"tier": "Standard"
},
"Premium": {
"family": null,
"name": "PremiumPool",
"tier": "Premium"
},
"GP_Gen5": {
"family": "Gen5",
"name": "GP_Gen5",
"tier": "GeneralPurpose"
},
"BC_Gen5": {
"family": "Gen5",
"name": "BC_Gen5",
"tier": "BusinessCritical"
}
},
"skuName": "[variables('editionToSkuMap')[parameters('edition')].name]",
"skuTier": "[variables('editionToSkuMap')[parameters('edition')].tier]",
"skuFamily": "[variables('editionToSkuMap')[parameters('edition')].family]"
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2020-02-02-preview",
"location": "[parameters('location')]",
"name": "[parameters('serverName')]",
"properties": {
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"version": "12.0"
}
},
{
"type": "Microsoft.Sql/servers/elasticPools",
"apiVersion": "2020-02-02-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers/', parameters('serverName'))]"
],
"location": "[parameters('location')]",
"name": "[concat(parameters('serverName'), '/', parameters('elasticPoolName'))]",
"sku": {
"name": "[variables('skuName')]",
"tier": "[variables('skuTier')]",
"family": "[variables('skuFamily')]",
"capacity": "[parameters('capacity')]"
},
"properties": {
"perDatabaseSettings": {
"minCapacity": "[parameters('databaseCapacityMin')]",
"maxCapacity": "[parameters('databaseCapacityMax')]"
}
}
},
{
"type": "Microsoft.Sql/servers/databases",
"name": "[concat(parameters('serverName'), '/', parameters('databasesNames')[copyIndex()])]",
"location": "[parameters('location')]",
"apiVersion": "2020-02-02-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers/', parameters('serverName'))]",
"[resourceId('Microsoft.Sql/servers/elasticpools', parameters('serverName'), parameters('elasticPoolName'))]"
],
"sku": {
"name": "ElasticPool",
"tier": "[variables('skuTier')]",
"capacity": 0
},
"properties": {
"collation": "[parameters('databaseCollation')]",
"elasticPoolId": "[resourceId('Microsoft.Sql/servers/elasticpools', parameters('serverName'), parameters('elasticPoolName'))]"
},
"copy": {
"name": "addDatabasesInElasticPool",
"count": "[length(parameters('databasesNames'))]"
}
},
{
"apiVersion": "2020-02-02-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers/', parameters('serverName'))]"
],
"location": "[parameters('location')]",
"name": "[concat(parameters('serverName'), '/', 'AllowAllWindowsAzureIps')]",
"properties": {
"endIpAddress": "0.0.0.0",
"startIpAddress": "0.0.0.0"
},
"type": "Microsoft.Sql/servers/firewallrules"
}
]
}
The deployment fails with this error
{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"InvalidTierSkuCombination","message":"The tier 'GeneralPurpose' does not support the sku 'SQLDB_GP_Gen5'."}]}
Please what can be issue here?
I think the error message explains the cause of the deployment failure
The tier 'GeneralPurpose' does not support the sku 'SQLDB_GP_Gen5'
The mapping of tier to sku is controlled by the input parameter edition, and the editionToSkuMap variable map, which indicates to me that the variable map is not correct. You'll likely need to dig into what the valid sku values are for a tier with the az CLI
az sql elastic-pool list-editions -l -o table
and update the variable mapping, then try to deploy again. It's probably worth opening an issue on the Azure Quickstart templates repository too
Please download this template (template.json & parameters.json) from GitHub that will allow you to create an Azure SQL Database Elastic Pool - General Purpose with one database included.

Microsoft.Compute/virtualMachines/extensions' has incorrect segment lengths

I'm unable to deploy this NESTED template because of an Custom Script Extension (CompDesc) that I've added to it. I am prompted with the following error when trying to deploy:
Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource 'CompDesc' for type 'Microsoft.Compute/virtualMachines/extensions' at line '207' and column '6' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-template/#resources for usage details.'.
As you can see it already has a DSC extension which I have tested and deployed perfectly fine, but I also need to add this CSE for a small .ps1 script.
I have checked out:
Azure website resource template error
and Set ARM Template Web appSetting
I have tried:
changing the name to 1 word
changing the type to 1 word
changing the name to [concat(parameters('vmName'),'/extension')]
changing the type to Microsoft.Compute/virtualMachines/extensions
nested the resource inside the VM resource, and then changed the name and type to one of the varieties I've tried
removed the CSE from the VM resource and placed it on its own (as it is now shown), and then changed the name and type to one of the varieties I've tried
I know it has something to do with the naming convention, but I'm unsure on how to fix it. Bear in mind, that this is a nested template. From what I read and understand from the error, nested templates must have identical segments as its resource name, which I've tried.
Please, any ideas?
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"adminUsername": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"computerDescription": {
"type": "string",
"metadata": {
"description": "The description name of the VM."
}
},
"nicName": {
"type": "string",
"metadata": {
"description": "The name of the VM nic"
}
},
"nodeConfigurationName": {
"type": "string",
"metadata": {
"description": "The name of the node configuration, on the Azure Automation DSC pull server, that this node will be configured as"
}
},
"projectTag": {
"type": "string",
"metadata": {
"description": "name of the Project"
}
},
"registrationKey": {
"type": "securestring",
"metadata": {
"description": "Registration key to use to onboard to the Azure Automation DSC pull/reporting server"
}
},
"registrationUrl": {
"type": "string",
"metadata": {
"description": "The URL to register against the DSC automation server"
}
},
"sasToken": {
"type": "securestring",
"metadata": {
"description": "Generated SAS token to be used."
}
},
"virtualNetworkName": {
"type": "string",
"metadata": {
"description": "name of the vNet"
}
},
"vmName": {
"type": "string",
"defaultValue": "myVM",
"metadata": {
"description": "The name of the VM resource"
}
},
"windowsOSVersion": {
"type": "string",
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
}
}
},
"variables": {
// Configuration for the VM
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"vmSize": "Standard_A2",
"vhdStorageAccountName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]",
"vhdStorageContainerName": "vhds",
"vhdStorageType": "Standard_LRS",
// Configuration for network
"publicIPAddressName": "myPublicIP",
"publicIPAddressType": "Dynamic",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]",
"subnetName": "default",
"vnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
// Configuration of the DSC
"allowModuleOverwrite": false,
"actionAfterReboot": "ContinueConfiguration",
"configurationFunction": "UpdateLCMforAAPull.ps1\\ConfigureLCMforAAPull",
"configurationMode": "ApplyAndAutoCorrect",
"configurationModeFrequencyMins": 15,
"modulesUrl": "[concat('REDACTED', parameters('sasToken'))]",
"refreshFrequencyMins": 30,
"rebootNodeIfNeeded": true,
"timestamp": "MM/dd/yyyy H:mm:ss tt"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('vhdStorageAccountName')]",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "StorageAccount"
},
"sku": {
"name": "[variables('vhdStorageType')]"
},
"kind": "Storage"
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "PublicIPAddress"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
}
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('nicName')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[concat(parameters('vmName'), parameters('projectTag'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('vhdStorageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"lun": 0,
"createOption": "Empty"
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob]"
}
}
}
},
{
"name": "CompDesc",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-30",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"tags": {
"displayName": "CompDesc"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat('REDACTED', parameters('sasToken'))]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File compdesc.ps1', ' ', '\"', parameters('computerDescription'), '\"')]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'),'/Microsoft.Powershell.DSC')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.19",
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"Items": {
"registrationKeyPrivate": "[parameters('registrationKey')]"
}
},
"settings": {
"ModulesUrl": "[variables('modulesUrl')]",
"SasToken": "",
"ConfigurationFunction": "[variables('configurationFunction')]",
"Properties": [
{
"Name": "RegistrationKey",
"Value": {
"UserName": "PLACEHOLDER_DONOTUSE",
"Password": "PrivateSettingsRef:registrationKeyPrivate"
},
"TypeName": "System.Management.Automation.PSCredential"
},
{
"Name": "RegistrationUrl",
"Value": "[parameters('registrationUrl')]",
"TypeName": "System.String"
},
{
"Name": "NodeConfigurationName",
"Value": "[parameters('nodeConfigurationName')]",
"TypeName": "System.String"
},
{
"Name": "ConfigurationMode",
"Value": "[variables('configurationMode')]",
"TypeName": "System.String"
},
{
"Name": "ConfigurationModeFrequencyMins",
"Value": "[variables('configurationModeFrequencyMins')]",
"TypeName": "System.Int32"
},
{
"Name": "RefreshFrequencyMins",
"Value": "[variables('refreshFrequencyMins')]",
"TypeName": "System.Int32"
},
{
"Name": "RebootNodeIfNeeded",
"Value": "[variables('rebootNodeIfNeeded')]",
"TypeName": "System.Boolean"
},
{
"Name": "ActionAfterReboot",
"Value": "[variables('actionAfterReboot')]",
"TypeName": "System.String"
},
{
"Name": "AllowModuleOverwrite",
"Value": "[variables('allowModuleOverwrite')]",
"TypeName": "System.Boolean"
},
{
"Name": "Timestamp",
"Value": "[variables('timestamp')]",
"TypeName": "System.String"
}
]
}
}
}
]
}
My god, an oversight by myself. I forgot to re-upload the nested template to blob storage once I made my changes. So dumb.
Anyway, for those that want to know;
https://github.com/blumu/azure-content/blob/master/articles/resource-manager-common-deployment-errors.md

How I create a VM from a custom Image using Azure Resource Manager

I've been using the Azure Classic portal for a while and I'm able to create VMs from my custom images w/o a problem.
Now I'm trying to use the new portal, when I go to create a new VM I don't see the option to use my images. How do I create a VM from one of my images?
Here is how to do it...
Assuming your Resource group is created and my infra config are follows-
custom template uri path- https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd
RG Name - myVMsRG
VNet Name - myVNET
VmName = mytestvm
userImageStorageAccountName = myvmstore
adminUsername = adminuser
adminPassword = PassWord123#
osDiskVhdUri = https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd
dnsLabelPrefix = mytestvm
osType = Windows
vmSize = Standard_D2
newOrExistingVnet = existing
newOrExistingVnetName = myVNET
newOrExistingSubnetName = mySubnet
First you need json template. I have configured for myself in this format. You can copy the same code and save with name deployvm.json in your D drive. Note: If your VNET name is different from myVNET please hard code the same in the template at the same position.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"customVmName": {
"type": "string",
"metadata": {
"description": "This is the name of the your VM"
}
},
"userImageStorageAccountName": {
"type": "string",
"metadata": {
"description": "This is the name of the your storage account"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the your user image"
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "DNS Label for the Public IP. Must be lowercase. It should match with the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$ or it will raise an error."
}
},
"adminUserName": {
"type": "string",
"metadata": {
"description": "User Name for the Virtual Machine"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"metadata": {
"description": "This is the OS that your VM will be running"
}
},
"vmSize": {
"type": "string",
"metadata": {
"description": "This is the size of your VM"
}
},
"newOrExistingVnet": {
"allowedValues": [ "new", "existing" ],
"type": "string",
"metadata": {
"description": "Select if this template needs a new VNet or will reference an existing VNet"
}
},
"newOrExistingVnetName": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "New or Existing VNet Name"
}
},
"newOrExistingSubnetName": {
"type": "string",
"defaultValue": "Subnet1",
"metadata": {
"description": "Subnet Name"
}
}
},
"variables": {
"publicIPAddressName": "[parameters('customVmName')]",
"vmName": "[parameters('customVmName')]",
"nicName": "[parameters('customVmName')]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"vnetID": "[resourceId('myVNET', 'Microsoft.Network/virtualNetworks', parameters('newOrExistingVnetName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('newOrExistingSubnetName'))]",
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"osDisk": {
"name": "[concat(variables('vmName'),'-osDisk')]",
"osType": "[parameters('osType')]",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "[parameters('osDiskVhdUri')]"
},
"vhd": {
"uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob, 'vhds/',variables('vmName'), uniquestring(resourceGroup().id), 'osDisk.vhd')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob)]"
}
}
}
}
]
}
Now use below powershell code to create your VM-
$paramList =
#{
"Params1" = #{ customVmName = "mytestvm" ; userImageStorageAccountName = "myvmstore" ; adminUsername = "adminuser" ; adminPassword = "PassWord123#" ; osDiskVhdUri = "https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd" ; dnsLabelPrefix = "mytestvm" ; osType ="Windows" ; vmSize = "Standard_D2" ; newOrExistingVnet = "existing" ; newOrExistingVnetName = "myVPN" ; newOrExistingSubnetName = "mySubnet"}
}
foreach ($keys in $paramList.Keys)
{
$paramvalues = $paramList.$keys
New-AzureRmResourceGroupDeployment -ResourceGroupName "myVMsRG" -TemplateFile "D:\deployvm.json" -TemplateParameterObject $paramValues
}
Reference- https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image
You could use Powershell for that or an ARM Template. There is really too much code to paste here, but even if the links I post will change, its easily searchable.
Copy your Custom Images from Azure Classic portal to new Portal ( Here everything is stored under a Resource Group) Storage Account.
Now you will be able to Create new VM using your Custom images through Azure CLI or PowerShell or ARM Template.

Resources