Azure ARM Template Deployment in existing Availability Set - azure

From the template below how do I add it to an existing Availability Set(Same resource group). I can't do this after VM creation so I need to do it here.
Getting error as
The Availability Set
'/subscriptions/XXXXXXXXXXX/resourceGroups/XXXXXXXXXXXX/providers/Microsoft.Com
pute/availabilitySets/XXXXXXX' cannot be found.
However it is available on portal. I can deploy VM manually.
{
"contentVersion": "1.0.0.0",
"parameters": {
SOME MORE PARAMETERS
"AvSet":{
"type": "string",
"defaultValue": "XXXXXXXXXXXXX"
},
},
"variables": {
"ExtensionLink": "[concat(parameters('containerUrl'),'/domainjoin_extension.json')]",
"subnetRef": "[resourceId(parameters('existingVnetResourceGroup'), 'Microsoft.Network/virtualNetworks/subnets', parameters('existingVnetName'), parameters('existingSubnetName'))]",
},
"resources": [{
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('virtualMachineName')]",
"apiVersion": "2017-03-30",
"location": "[resourceGroup().location]",
"tags": "[parameters('tagValues')]",
"properties": {
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[parameters('publisher')]",
"offer": "[parameters('offer')]",
"sku": "[parameters('OSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage",
"diskSizeGB": "[parameters('diskSizeGB')]",
"managedDisk": {
"storageAccountType": "[parameters('storageAccountType')]"
},
"name": "[parameters('osDiskName')]"
}
},
"networkProfile": {
"networkInterfaces": [{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId(parameters('existingStorageRgName'), 'Microsoft.Storage/storageAccounts', parameters('existingDiagnosticsStorageAccountName')), '2015-06-15').primaryEndpoints['blob']]"
}
},
"AvailabilitySet" : {
"id": "[resourceId('Microsoft.Compute/availabilitySets', parameters('AvSet'))]"
},
},
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
]
},
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('networkInterfaceName')]",
"apiVersion": "2016-09-01",
"location": "[resourceGroup().location]",
"tags": "[parameters('tagValues')]",
"properties": {
"ipConfigurations": [{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic"
}
}]
}
},
{
"apiVersion": "2017-05-10",
"name": "linked1",
"condition": "[equals(parameters('extensionCreateorNot'),'yes')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "incremental",
"templateLink": {
"uri": "[variables('ExtensionLink')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"virtualMachineName": {
"value": "[string(parameters('virtualMachineName'))]"
},
"domainJoinUserName": {
"value": "[string(parameters('domainJoinUserName'))]"
},
"domainJoinUserPassword": {
"value": "[string(parameters('domainJoinUserPassword'))]"
},
"domainFQDN": {
"value": "[string(parameters('domainFQDN'))]"
},
"ouPath": {
"value": "[string(parameters('ouPath'))]"
}
}
},
"dependsOn": [
"linked2",
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]",
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
]
},
{
"apiVersion": "2017-05-10",
"name": "linked2",
"condition": "[equals(parameters('dataDisksattachornot'),'yes')]",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "incremental",
"templateLink": {
"uri": "[variables('attachDataDiskExtensionLink')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"virtualMachineName": {
"value": "[string(parameters('virtualMachineName'))]"
},
"sizeOfDataDisksInGB": {
"value": "[array(parameters('sizeOfDataDisksInGB'))]"
},
"tagValues": {
"value": "[parameters('tagValues')]"
}
}
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]",
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
]
}
],
"outputs": {
"adminUsername": {
"type": "String",
"value": "[parameters('adminUsername')]"
},
"virtualMachineName": {
"type": "String",
"value": "[parameters('virtualMachineName')]"
},
"networkInterface": {
"type": "string",
"value": "[reference(concat(parameters('networkInterfaceName'))).ipConfigurations[0].properties.privateIPAddress]"
}
}
}

if you want to add vm to existing availabilty set - you have to give it its resourceId, that is. add the following parameter to vm properties:
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets', 'existing_availability_set_name')]"
},
example:
https://github.com/Azure/azure-quickstart-templates/blob/master/201-2-vms-loadbalancer-natrules/azuredeploy.json#L264

Related

ARM : Get network Interface Private IP and Default Gateway

im deploying an ARM template for a virtual machine with network interfaces
i have a .sh script that needs parameters to be passed to it
parameters :
NIC private ip
NIC default Gateway
nic template :
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-06-01",
"name": "[parameters('nic2name')]",
"location": "[parameters('location')]",
"dependsOn": [
"[parameters('virtualNetworkName')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
},
"primary": true
}
}
],
"primary": false
}
}
im sitting variables to get this parameters but idk how to get them
"smnet_dev": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nic2name')).ipConfigurations]",
"smnet_dflt_gw": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nic2name')).<default gateway>]"
i hope someone can guide me to the right direction
AFAIK, We can not give it directly instead of that we can use PowerShell script or bicep which will retrieve the value of nic and put it in variable.
In ARM while we are creating resources (e.g virtual machine with nic) we can add the variable as following and then we can deploy the NIC with gateways.
Things we have tried to create a virtual Machine with nic and provide the variable as shown below it got succeed .
You can use the below template by passing your required name in parameter file for the Automation.
Template.json:-
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"enableAcceleratedNetworking": {
"type": "bool"
},
"networkSecurityGroupName": {
"type": "string"
},
"networkSecurityGroupRules": {
"type": "array"
},
"subnetName": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"addressPrefixes": {
"type": "array"
},
"subnets": {
"type": "array"
},
"publicIpAddressName": {
"type": "string"
},
"publicIpAddressType": {
"type": "string"
},
"publicIpAddressSku": {
"type": "string"
},
"pipDeleteOption": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"virtualMachineComputerName": {
"type": "string"
},
"virtualMachineRG": {
"type": "string"
},
"osDiskType": {
"type": "string"
},
"osDiskDeleteOption": {
"type": "string"
},
"virtualMachineSize": {
"type": "string"
},
"nicDeleteOption": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "secureString"
},
"patchMode": {
"type": "string"
},
"enableHotpatching": {
"type": "bool"
},
"tags": {
"type": "object"
}
},
"variables": {
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetName": "[parameters('virtualNetworkName')]",
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2021-03-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]",
"properties": {
"deleteOption": "[parameters('pipDeleteOption')]"
}
}
}
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
},
"tags": "[parameters('tags')]"
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[parameters('networkSecurityGroupRules')]"
},
"tags": "[parameters('tags')]"
},
{
"name": "[parameters('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-11-01",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": "[parameters('subnets')]"
},
"tags": "[parameters('tags')]"
},
{
"name": "[parameters('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
},
"sku": {
"name": "[parameters('publicIpAddressSku')]"
},
"tags": "[parameters('tags')]"
},
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
},
"deleteOption": "[parameters('osDiskDeleteOption')]"
},
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-datacenter-gensecond",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]",
"properties": {
"deleteOption": "[parameters('nicDeleteOption')]"
}
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineComputerName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVmAgent": true,
"patchSettings": {
"enableHotpatching": "[parameters('enableHotpatching')]",
"patchMode": "[parameters('patchMode')]"
}
}
},
"licenseType": "Windows_Server"
},
"tags": "[parameters('tags')]"
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
From this aforementioned script here is our NIC template ;
"resources": [
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2021-03-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]",
"properties": {
"deleteOption": "[parameters('pipDeleteOption')]"
}
}
}
}
],
OUTPUT SCREENSHOT FOR REFERENCE:-
For more information please refer the below links:-
SIMILAR SO THREAD|ARM Template - Get a private ip address from a network interface id & Cannot find VirtualNetwork with name' creating a 'Microsoft.Web/hostingEnvironments' resource .

Assigning Static Ip to nic(copy loop) in ARM template

I am trying to change dynamic private ip allocated VM to Static IP via ARM template.
It works for a single vm. But facing issue for multiple VM's deployment. I am trying nested deployment.
The error I am facing is: The template reference "nic-"somevmname"-01" is
not valid: could not find template resource or resource copy with this name.
I am not able to figure out what is wrong with the nested resource
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VnetResourceGroup": {
"type": "string"
},
"VnetName": {
"type": "string"
},
"SubnetName": {
"type": "string"
},
"adminusername": {
"type": "string",
"metadata": {
"description": "Admin username for VM"
}
},
"adminpassword": {
"type": "string"
},
"vm-name": {
"type": "string",
"metadata": {
"description": ""
}
},
"virtualMachineCount": {
"type": "int",
"metadata": {
"description": "Number of Virtual machines to be deployed"
}
},
"vmSize": {
"type": "string",
"metadata": {
"description": "description"
}
},
"vm-image-name": {
"type": "string",
"metadata": {
"description": "description"
}
},
"vm-image-rg": {
"type": "string",
"metadata": {
"description": "description"
}
},
"dataDisksize": {
"type": "int"
},
"datadisks-count": {
"type": "int"
},
"osDiskType": {
"type": "string"
},
"osDiskSize": {
"type": "int",
"metadata": {
"description": "description"
}
},
"maxAvailabilityzones": {
"type": "int",
"metadata": {
"description": "description"
}
}
},
"variables": {
"ImageReferenceId": "[concat(subscription().id, '/resourceGroups/', parameters('vm-image-rg'), '/providers/Microsoft.Compute/images/', parameters('vm-image-name'))]",
"vnetId": "[concat(subscription().id, '/resourceGroups/', parameters('VnetResourceGroup'), '/providers/Microsoft.Network/virtualNetworks/', parameters('VnetName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat('nic-',parameters('vm-name'),'-0', copyIndex(1))]",
"apiVersion": "2018-11-01",
"location": "[resourceGroup().location]",
"copy": {
"name": "nicLoop",
"count": "[parameters('virtualMachineCount')]"
},
"properties": {
"enableAcceleratedNetworking": true,
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat(parameters('vm-name'),'-0', copyIndex(1))]",
"apiVersion": "2020-06-01",
"location": "[resourceGroup().location]",
"zones": [
"[string(add(mod(copyIndex(0), parameters('maxAvailabilityzones')), 1))]"
],
"copy": {
"name": "virtualMachineLoop",
"count": "[parameters('virtualMachineCount')]"
},
"dependsOn": [
"nicLoop"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat(parameters('vm-name'),'-0', copyIndex(1))]",
"adminusername": "[parameters('adminusername')]",
"adminPassword": "[parameters('adminpassword')]"
},
"storageProfile": {
"copy": [
{
"name": "dataDisks",
"count": "[parameters('datadisks-count')]",
"input": {
"lun": "[copyIndex('dataDisks')]",
"name": "[concat('dataDisk',copyIndex('dataDisks',1),'-',parameters('vm-name'),'-0',copyIndex(1))]",
"createOption": "Empty",
"diskSizeGB": "[parameters('dataDisksize')]"
}
}
],
"imageReference": { "id": "[variables('ImageReferenceId')]" },
"osDisk": {
"name": "[concat('osdisk-',parameters('vm-name'),'-0', copyIndex(1))]",
"createOption": "FromImage",
"caching": "ReadWrite",
"diskSizeGB": "[parameters('osDiskSize')]",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat('nic-',parameters('vm-name'),'-0', copyIndex(1)))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "StaticIP",
"apiVersion": "2020-06-01",
"dependsOn": [
"nicLoop",
"virtualMachineLoop"
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"SubnetRef": {
"value": "[variables('SubnetRef')]"
},
"virtualMachineCount": {
"value": "[parameters('virtualMachineCount')]"
},
"vm-name": {
"value": "[parameters('vm-name')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subnetRef": {
"type": "string"
},
"virtualMachineCount": {
"type": "int",
"metadata": {
"description": "Number of Virtual machines to be deployed"
}
},
"vm-name": {
"type": "string",
"metadata": {
"description": "description"
}
}
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat('assignstaticip',copyIndex(1))]",
"apiVersion": "2020-05-01",
"location": "[resourceGroup().location]",
"copy": {
"name": "nicStaticIpLoop",
"count": "[parameters('virtualMachineCount')]"
},
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[reference(concat('nic-',parameters('vm-name'),'-0', copyIndex('nicStaticIpLoop',1))).ipConfigurations[0].properties.privateIPAddress]",
"subnet": {
"id": "[parameters('subnetRef')]"
}
}
}
]
}
}
]
}
}
}
],
"outputs": {
"vm-ipaddress": {
"type": "array",
"copy": {
"count": "[parameters('virtualMachineCount')]",
"input": "[reference(concat('nic-',parameters('vm-name'),'-0', copyIndex(1))).ipConfigurations[0].properties.privateIPAddress]"
}
},
"vm-name": {
"type": "array",
"copy": {
"count": "[parameters('virtualMachineCount')]",
"input": "[concat(parameters('vm-name'),'-0', copyIndex(1))]"
}
}
}
}
Thank you #Anonymouus, for sharing the update . And bring the question for how to change dynamic private ip allocated VM to Static IP via ARM template, It will be really helpful for the SO community for similar issue who encounter the same so that they can find & fix their problem by posting it as an answer .
As stated in the given Blog which is Author by #Praveen.
To change the dynamic IP to static IP through ARM TEMPLATE we can use the below example of template,
ARM TEMPLATE:-
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2018-05-01",
"name": "[concat('StaticIp', copyIndex())]",
"dependsOn": [
"nicLoop"
],
"copy": {
"name": "ipLoop",
"count": "[parameters('ServerInstanceCount')]"
},
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(parameters('ServerNamePrefix'),padLeft(copyIndex(),3,'0'),'-NIC')]",
"apiVersion": "2018-03-01",
"location": "[resourceGroup().location]",
"tags": "[parameters('tagValues')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[reference(concat(parameters('ServerNamePrefix'),padLeft(copyIndex(),3,'0'),'-NIC')).ipConfigurations[0].properties.privateIPAddress]",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
],
"enableAcceleratedNetworking": true
}
}
]
}
}
}
For more information please refer the below links:-
SO THREAD| Static ip addresses on Azure & Nested Copy loop using ARM Template.

Azure CLI - az deployment group create - SubscriptionNotAuthorizedForImage Error

In Azure when deploying via 'az deployment group create' I get an error since a few days.
The ressource group is created in 'West Europe' - Region
Here is my command:
az deployment group create --resource-group rg-UITest-$(Build.BuildId) --template-file WorkingCopy/hook/AzureDevOps/e5_setupvm_template.json --parameters WorkingCopy/hook/AzureDevOps/e5_setupvm_parameters.json --parameters adminPassword=$env:PASSWORD_FOR_VIRTUALMACHINE
With debug Flag I get the following information
2021-06-01T08:49:28.2629276Z DEBUG: cli.azure.cli.core.sdk.policies: Response content:
2021-06-01T08:49:28.2630595Z DEBUG: cli.azure.cli.core.sdk.policies: {"status":"Failed","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":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"SubscriptionNotAuthorizedForImage\",\r\n \"message\": \"The subscription is not authorized.\",\r\n \"target\": \"imageReference\"\r\n }\r\n}"}]}}
Here is the template.json imageReference:
"imageReference": {
"publisher": "MicrosoftWindowsDesktop",
"offer": "Windows-10",
"sku": "rs5-pro",
"version": "latest"
}
Just a few days ago it still worked. I am not sure what has changed or what the problem is.
Here the full template:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"networkSecurityGroupRules": {
"type": "array"
},
"subnetName": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"addressPrefixes": {
"type": "array"
},
"subnets": {
"type": "array"
},
"publicIpAddressName": {
"type": "string"
},
"publicIpAddressType": {
"type": "string"
},
"publicIpAddressSku": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"virtualMachineRG": {
"type": "string"
},
"osDiskType": {
"type": "string"
},
"virtualMachineSize": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "secureString"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"diagnosticsStorageAccountType": {
"type": "string"
},
"diagnosticsStorageAccountKind": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
},
"autoShutdownNotificationLocale": {
"type": "string"
},
"autoShutdownNotificationEmail": {
"type": "string"
},
"virtualNetworks_rg_scaleset4_vnet_externalid": {
"defaultValue": "/subscriptions/fdcf7f70-e042-4c2e-aff0-c933b9a44779/resourceGroups/rg-scaleset4/providers/Microsoft.Network/virtualNetworks/rg-scaleset4-vnet",
"type": "String"
}
},
"variables": {
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[concat(parameters('virtualNetworks_rg_scaleset4_vnet_externalid'), '/subnets/default')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
}
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[parameters('networkSecurityGroupRules')]"
}
},
{
"name": "[parameters('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-09-01",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": "[parameters('subnets')]"
}
},
{
"name": "[parameters('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
},
"sku": {
"name": "[parameters('publicIpAddressSku')]"
}
},
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
"[concat('Microsoft.Storage/storageAccounts/', parameters('diagnosticsStorageAccountName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
},
"imageReference": {
"publisher": "MicrosoftWindowsDesktop",
"offer": "Windows-10",
"sku": "rs5-pro",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVmAgent": true,
"additionalUnattendContent": [
{
"passName": "oobesystem",
"componentName": "Microsoft-Windows-Shell-Setup",
"settingName": "AutoLogon",
"content": "[concat('<AutoLogon><Password><Value>', parameters('adminPassword'), '</Value><PlainText>true</PlainText></Password><Enabled>true</Enabled><Username>', parameters('adminUsername'), '</Username></AutoLogon>')]"
}
]
}
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
}
}
}
},
{
"name": "[parameters('diagnosticsStorageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"location": "[parameters('location')]",
"properties": {},
"kind": "[parameters('diagnosticsStorageAccountKind')]",
"sku": {
"name": "[parameters('diagnosticsStorageAccountType')]"
}
},
{
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
],
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"notificationLocale": "[parameters('autoShutdownNotificationLocale')]",
"timeInMinutes": "30",
"emailRecipient": "[parameters('autoShutdownNotificationEmail')]"
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
Its Normal this image is no logger available,
When having this type of issue try to create it via the web interface as you will have the available SKU
Note : the listed image via az command is not always up to date
az vm image list-skus --location 'westeurope' --offer 'Windows-10' --publisher 'MicrosoftWindowsDesktop'
Better use
source_image_reference {
publisher = "MicrosoftWindowsDesktop"
offer = "Windows-10"
version = "latest"
sku = "20h2-pro"
}

"Provisioning VM failed. Require plan information" when creating an image from image

I was trying to create a GPU device from an image of another GPU device. But, Azure keeps showing me the same error:
So, what exactly is the Plan information is Azure talking about?. Also, is there some way to bring up a generalized VM?
Template which I'm using: [though I am trying directly from the portal]
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "String"
},
"virtualMachineName": {
"type": "String"
},
"virtualMachineSize": {
"type": "String"
},
"adminUsername": {
"type": "String"
},
"virtualNetworkName": {
"type": "String"
},
"networkInterfaceName": {
"type": "String"
},
"networkSecurityGroupName": {
"type": "String"
},
"adminPassword": {
"type": "SecureString"
},
"diagnosticsStorageAccountName": {
"type": "String"
},
"diagnosticsStorageAccountId": {
"type": "String"
},
"subnetName": {
"type": "String"
},
"publicIpAddressName": {
"type": "String"
},
"publicIpAddressType": {
"type": "String"
},
"publicIpAddressSku": {
"type": "String"
}
},
"variables": {
"vnetId": "[resourceId('datasciencesdevNew','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('virtualMachineName')]",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"properties": {
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"imageReference": {
"id": "/subscriptions/dfbb6f84-8e85-42f9-862b-10d778e0b4a5/resourceGroups/datasciencesdev/providers/Microsoft.Compute/images/Image-Aug10"
},
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
}
}
},
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
]
},
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('networkInterfaceName')]",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId('datasciencesdevNew','Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('datasciencesdevNew', 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
}
},
"dependsOn": [
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
]
},
{
"type": "Microsoft.Network/publicIpAddresses",
"sku": {
"name": "[parameters('publicIpAddressSku')]"
},
"name": "[parameters('publicIpAddressName')]",
"apiVersion": "2017-08-01",
"location": "[parameters('location')]",
"properties": {
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
}
}
],
"outputs": {
"adminUsername": {
"type": "String",
"value": "[parameters('adminUsername')]"
}
}
}
You need to add plan information to you VM definition. You can get it from your previous VM. it looks something like this:
"plan": {
"publisher": "paloaltonetworks",
"name": "bundle1",
"product": "vmseries1"
}
this is at the root of the VM resource definition. name\product\publisher are here for reference

InvalidResourceReference when deploying ARM template for VM

I downloaded ARM template from Azure for deploying VM. I did not modify the script in any way. When I run the deploy.ps1 script I get the following error
New-AzureRmResourceGroupDeployment : 1:05:56 PM - Resource Microsoft.Network/networkInterfaces 'win2016vm293' failed
with message '{
"error": {
"code": "InvalidResourceReference",
"message": "Resource /subscriptions/<subscriptionId>/resourceGroups/win2016vm2/providers/Micros
oft.Network/networkSecurityGroups/Win2016vm2-nsg referenced by resource /subscriptions/<subscriptionId>/resourceGroups/Win2016FromScript/providers/Microsoft.Network/networkInterfaces/win2016vm293 was not found.
Please make sure that the referenced resource exists, and that both resources are in the same region.",
"details": []
}
}'
The following is the template.js file.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"virtualMachineSize": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"addressPrefix": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"subnetPrefix": {
"type": "string"
},
"publicIpAddressName": {
"type": "string"
},
"publicIpAddressType": {
"type": "string"
},
"publicIpAddressSku": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('win2016vm2','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"provisionVmAgent": "true"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"dataDisks": []
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
}
}
},
{
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
}
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
},
{
"name": "[parameters('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2018-02-01",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
}
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]",
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId('win2016vm2','Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
}
}
}
],
"enableAcceleratedNetworking": true,
"networkSecurityGroup": {
"id": "[resourceId('win2016vm2', 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
}
}
},
{
"name": "[parameters('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2017-08-01",
"location": "[parameters('location')]",
"properties": {
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
},
"sku": {
"name": "[parameters('publicIpAddressSku')]"
}
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2018-01-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "RDP",
"properties": {
"priority": 300,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceApplicationSecurityGroups": [],
"destinationApplicationSecurityGroups": [],
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "3389"
}
}
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
After running the script I see that only Win2016vm2-nsg (Network security group), as well as the IP and the VNet resources are created.
In the template, the section for creating Microsoft.Network/networkInterfaces contains dependsOn section with networkSecurityGroups resource name in it, which seems correct. So I'm not sure what is wrong here.
Your template is using hardcoded resourceGroup name for several resources, you need to amend that, change 'win2016vm2' to a resourceGroup you are deploying to, or remove resourceGroup from resourceId() function altogether.

Resources