I am setting up my first ARM template to create a simple windows Virtiual Machine via Azure DevOps.
I have the template file and parameters file and have set a pipeline variable to avoid the complexities of an Azure KeyVault as the first step.
I have setup a pipeline variable Password and locked it.
The Virtual Machine gets setup in my Azure Account no problem but I cannot log in to it. It will not accept the credentials I am passing in. If I reset the password using portal.azure.com all is well. Something is not right about what I am doing in passing my ARM template the adminPassword.
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"
},
"virtualMachineComputerName": {
"type": "string"
},
"virtualMachineRG": {
"type": "string"
},
"osDiskType": {
"type": "string"
},
"dataDisks": {
"type": "array"
},
"dataDiskResources": {
"type": "array"
},
"virtualMachineSize": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "secureString"
},
"patchMode": {
"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": "2018-10-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'))]"
}
}
}
],
"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('dataDiskResources')[copyIndex()].name]",
"type": "Microsoft.Compute/disks",
"apiVersion": "2020-09-30",
"location": "[parameters('location')]",
"properties": "[parameters('dataDiskResources')[copyIndex()].properties]",
"sku": {
"name": "[parameters('dataDiskResources')[copyIndex()].sku]"
},
"copy": {
"name": "managedDiskResources",
"count": "[length(parameters('dataDiskResources'))]"
}
},
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-12-01",
"location": "[parameters('location')]",
"dependsOn": [
"managedDiskResources",
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
},
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"copy": [
{
"name": "dataDisks",
"count": "[length(parameters('dataDisks'))]",
"input": {
"lun": "[parameters('dataDisks')[copyIndex('dataDisks')].lun]",
"createOption": "[parameters('dataDisks')[copyIndex('dataDisks')].createOption]",
"caching": "[parameters('dataDisks')[copyIndex('dataDisks')].caching]",
"diskSizeGB": "[parameters('dataDisks')[copyIndex('dataDisks')].diskSizeGB]",
"managedDisk": {
"id": "[coalesce(parameters('dataDisks')[copyIndex('dataDisks')].id, if(equals(parameters('dataDisks')[copyIndex('dataDisks')].name, json('null')), json('null'), resourceId('Microsoft.Compute/disks', parameters('dataDisks')[copyIndex('dataDisks')].name)))]",
"storageAccountType": "[parameters('dataDisks')[copyIndex('dataDisks')].storageAccountType]"
},
"writeAcceleratorEnabled": "[parameters('dataDisks')[copyIndex('dataDisks')].writeAcceleratorEnabled]"
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineComputerName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"enableAutomaticUpdates": true,
"provisionVmAgent": true,
"patchSettings": {
"patchMode": "[parameters('patchMode')]"
}
}
},
"priority": "Spot",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": 0.08
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
parameters.json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "uksouth"
},
"networkInterfaceName": {
"value": "machine1587"
},
"networkSecurityGroupName": {
"value": "Machine1-nsg"
},
"networkSecurityGroupRules": {
"value": [
{
"name": "RDP",
"properties": {
"priority": 300,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "3389"
}
}
]
},
"subnetName": {
"value": "default"
},
"virtualNetworkName": {
"value": "AzureTest-vnet"
},
"addressPrefixes": {
"value": [
"10.0.0.0/24"
]
},
"subnets": {
"value": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
},
"publicIpAddressName": {
"value": "Machine1-ip"
},
"publicIpAddressType": {
"value": "Dynamic"
},
"publicIpAddressSku": {
"value": "Basic"
},
"virtualMachineName": {
"value": "Machine1"
},
"virtualMachineComputerName": {
"value": "Machine1"
},
"virtualMachineRG": {
"value": "AzureTest"
},
"osDiskType": {
"value": "Standard_LRS"
},
"dataDisks": {
"value": [
{
"lun": 0,
"createOption": "attach",
"caching": "ReadOnly",
"writeAcceleratorEnabled": false,
"id": null,
"name": "Machine1_DataDisk_0",
"storageAccountType": null,
"diskSizeGB": null,
"diskEncryptionSet": null
}
]
},
"dataDiskResources": {
"value": [
{
"name": "Machine1_DataDisk_0",
"sku": "Standard_LRS",
"properties": {
"diskSizeGB": 64,
"creationData": {
"createOption": "empty"
}
}
}
]
},
"virtualMachineSize": {
"value": "Standard_DS1_v2"
},
"adminUsername": {
"value": "LocalAdminUserName"
},
"adminPassword": {
"value": null
},
"patchMode": {
"value": "AutomaticByOS"
}
}
}
steps:
- task: AzureResourceManagerTemplateDeployment#3
displayName: 'ARM Template deployment: Resource Group scope'
inputs:
azureResourceManagerConnection: 'Pay-As-You-Go (xxxxxxxxxxxxxxx)'
subscriptionId: 'xxxxxxxxxxxxxxx'
resourceGroupName: AzureTest
location: 'UK South'
csmFile: '$(System.DefaultWorkingDirectory)/_Azure/First Virtual Machine/template.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/_Azure/First Virtual Machine/parameters.json'
overrideParameters: '-adminPassword "$(Password)"'
That all looks fine on the surface, but your template schema is no longer on the supported schemas list for virtualMachines at Resource Types. I'm wondering if you might get traction with a later template version?
Related
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"
}
I'm trying to create a windows Azure VM Scale Set that auto provisions a formatted attached data disk using the MS guide here: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-attached-disks
No matter what I do I see to get this error:
9:14:16 PM - The deployment 'testvmss' failed with error(s). Showing
1 out of 1 error(s). Status
| Message: VM has reported a failure when processing extension 'customScript'. Error message: "Invalid
| Configuration - CommandToExecute is not specified in the configuration; it must be specified in either
| the protected or public configuration section" More information on troubleshooting is available at
| https://aka.ms/VMExtensionCSEWindowsTroubleshoot (Code:VMExtensionProvisioningError) CorrelationId:
| 3294f49a-23f0-4634-aba0-3bb0e814659e
I've tried:
moving the "commandToExecute" into the protected config area
"typeHandlerVersion" numbers
moving commandToExecute outside of the "settings" section
using case corrected "CommandToExecute"
Simplifying the powershell statement to "powershell echo test"
Searching google for the error message, better/different examples, etc.
Here is the specific section of the ARM:
"extensionProfile": {
"extensions": [
{
"name": "customScript",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/prepare_vm_disks.ps1"],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File prepare_vm_disks.ps1"
}
}
}
]
}
And for reference, here is the full ARM:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineScaleSetName": {
"type": "string"
},
"virtualMachineScaleSetRG": {
"type": "string"
},
"singlePlacementGroup": {
"type": "string"
},
"instanceSize": {
"type": "string"
},
"instanceCount": {
"type": "string"
},
"upgradeMode": {
"type": "string"
},
"priority": {
"type": "string"
},
"enableAcceleratedNetworking": {
"type": "string"
},
"subnetId": {
"type": "string"
},
"osDiskType": {
"type": "string"
},
"dataDisks": {
"type": "array"
},
"addressPrefixes": {
"type": "array"
},
"subnets": {
"type": "array"
},
"virtualNetworkId": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkSecurityGroups": {
"type": "array"
},
"networkInterfaceConfigurations": {
"type": "array"
},
"vmName": {
"type": "string"
},
"scaleInPolicy": {
"type": "object"
},
"overprovision": {
"type": "bool"
},
"upgradePolicy": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "secureString"
},
"platformFaultDomainCount": {
"type": "string"
}
},
"variables": {
"storageApiVersion": "2019-04-01",
"namingInfix": "[toLower(substring(concat(parameters('virtualMachineScaleSetName'), uniqueString(resourceGroup().id)), 0, 9))]"
},
"resources": [
{
"name": "[parameters('virtualNetworkName')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-09-01",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": "[parameters('subnets')]"
}
},
{
"name": "[parameters('networkSecurityGroups')[copyIndex()].name]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-02-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[parameters('networkSecurityGroups')[copyIndex()].rules]"
},
"copy": {
"name": "networkSecurityGroups",
"count": "[length(parameters('networkSecurityGroups'))]"
}
},
{
"name": "[parameters('virtualMachineScaleSetName')]",
"type": "Microsoft.Compute/virtualMachineScaleSets",
"apiVersion": "2019-12-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"networkSecurityGroups",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]"
],
"sku": {
"name": "[parameters('instanceSize')]",
"capacity": "[int(parameters('instanceCount'))]"
},
"properties": {
"overprovision": "[parameters('overprovision')]",
"upgradePolicy": {
"mode": "[parameters('upgradePolicy')]"
},
"singlePlacementGroup": "[parameters('singlePlacementGroup')]",
"virtualMachineProfile": {
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
},
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"copy": [
{
"name": "dataDisks",
"count": "[length(parameters('dataDisks'))]",
"input": {
"lun": "[parameters('dataDisks')[copyIndex('dataDisks')].lun]",
"createOption": "[parameters('dataDisks')[copyIndex('dataDisks')].createOption]",
"caching": "[parameters('dataDisks')[copyIndex('dataDisks')].caching]",
"writeAcceleratorEnabled": "[parameters('dataDisks')[copyIndex('dataDisks')].writeAcceleratorEnabled]",
"diskSizeGB": "[parameters('dataDisks')[copyIndex('dataDisks')].diskSizeGB]",
"managedDisk": {
"storageAccountType": "[parameters('dataDisks')[copyIndex('dataDisks')].storageAccountType]",
"diskEncryptionSet": "[parameters('dataDisks')[copyIndex('dataDisks')].diskEncryptionSet]"
},
"diskIOPSReadWrite": "[if(equals( parameters('dataDisks')[copyIndex('dataDisks')].diskIOPSReadWrite, -1), json('null'),parameters('dataDisks')[copyIndex('dataDisks')].diskIOPSReadWrite)]",
"diskMBpsReadWrite": "[if(equals( parameters('dataDisks')[copyIndex('dataDisks')].diskMBpsReadWrite, -1), json('null'),parameters('dataDisks')[copyIndex('dataDisks')].diskMBpsReadWrite)]"
}
}
]
},
"priority": "[parameters('priority')]",
"networkProfile": {
"copy": [
{
"name": "networkInterfaceConfigurations",
"count": "[length(parameters('networkInterfaceConfigurations'))]",
"input": {
"name": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].name]",
"properties": {
"primary": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].primary]",
"enableAcceleratedNetworking": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].enableAcceleratedNetworking]",
"ipConfigurations": [
{
"name": "[concat(parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].name, '-defaultIpConfiguration')]",
"properties": {
"subnet": {
"id": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].subnetId]"
},
"primary": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].primary]",
"applicationGatewayBackendAddressPools": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].applicationGatewayBackendAddressPools]",
"loadBalancerBackendAddressPools": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].loadBalancerBackendAddressPools]",
"loadBalancerInboundNatPools": "[parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].loadBalancerInboundNatPools]",
"publicIPAddressConfiguration": "[if( equals( parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].pipName, ''), json('null'), union(json(concat('{\"name\": \"', parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].pipName, '\"}'))\n ,json('{\"properties\": { \"idleTimeoutInMinutes\": 15}}')))]"
}
}
],
"networkSecurityGroup": "[if( equals( parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].nsgId, ''), json('null'),json(concat('{\"id\": \"', parameters('networkInterfaceConfigurations')[copyIndex('networkInterfaceConfigurations')].nsgId, '\"}')))]"
}
}
}
]
},
"extensionProfile": {
"extensions": [
{
"name": "customScript",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/prepare_vm_disks.ps1"],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File prepare_vm_disks.ps1"
}
}
}
]
},
"osProfile": {
"computerNamePrefix": "[variables('namingInfix')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"provisionVmAgent": true
}
}
},
"scaleInPolicy": "[parameters('scaleInPolicy')]",
"platformFaultDomainCount": "[parameters('platformFaultDomainCount')]"
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
Any help is greatly appreciated, thanks!
I had the same issue with VMSS Managed Disk and Service Fabric, because there is a problem with the last commit (from last September) - Here you can find an open issue about it.
Until this issue would be solved you can still use the script extension with link to previous version as I did:
https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/fdc643759c9aa7e9259da10575e67dc1368e4e9f/prepare_vm_disks.ps1
Add this script extension to the extensionProfile of the virtualMachineProfile of the scale set:
{
"name": "customScript",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/fdc643759c9aa7e9259da10575e67dc1368e4e9f/prepare_vm_disks.ps1"
],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File prepare_vm_disks.ps1"
}
}
}
As the MS guide template, you need to include a dataDisks section in the storageProfile of the Microsoft.Compute/virtualMachineScaleSets resource(s) and deploy the template.
Here is a working template for your references:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmSku": {
"type": "string",
"defaultValue": "Standard_A1_v2",
"metadata": {
"description": "Size of VMs in the VM Scale Set."
}
},
"windowsOSVersion": {
"type": "string",
"defaultValue": "2016-Datacenter"
},
"vmssName": {
"type": "string",
"minLength": 3,
"maxLength": 61
},
"instanceCount": {
"type": "int",
"defaultValue": 3,
"minValue": 1,
"maxValue": 100,
"metadata": {
"description": "Number of VM instances (100 or less)."
}
},
"singlePlacementGroup": {
"type": "bool",
"defaultValue": true
},
"adminUsername": {
"type": "string",
"defaultValue": "vmssadmin"
},
"adminPassword": {
"type": "securestring"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"platformFaultDomainCount": {
"type": "int",
"defaultValue": 1
}
},
"variables": {
"namingInfix": "[toLower(substring(concat(parameters('vmssName'), uniqueString(resourceGroup().id)), 0, 9))]",
"longNamingInfix": "[toLower(parameters('vmssName'))]",
"addressPrefix": "10.0.0.0/16",
"subnetPrefix": "10.0.0.0/24",
"virtualNetworkName": "[concat(variables('namingInfix'), 'vnet')]",
"publicIPAddressName": "[concat(variables('namingInfix'), 'pip')]",
"subnetName": "[concat(variables('namingInfix'), 'subnet')]",
"loadBalancerName": "[concat(variables('namingInfix'), 'lb')]",
"publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]",
"lbProbeID": "[resourceId('Microsoft.Network/loadBalancers/probes',variables('loadBalancerName'), 'tcpProbe')]",
"natPoolName": "[concat(variables('namingInfix'), 'natpool')]",
"bePoolName": "[concat(variables('namingInfix'), 'bepool')]",
"lbPoolID": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools',variables('loadBalancerName'),variables('bePoolName'))]",
"natStartPort": 50000,
"natEndPort": 50119,
"natBackendPort": 3389,
"nicName": "[concat(variables('namingInfix'), 'nic')]",
"ipConfigName": "[concat(variables('namingInfix'), 'ipconfig')]",
"frontEndIPConfigID": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations',variables('loadBalancerName'),'loadBalancerFrontEnd')]",
"osType": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"imageReference": "[variables('osType')]"
},
"resources": [
{
"type": "Microsoft.Network/loadBalancers",
"apiVersion": "2020-06-01",
"name": "[variables('loadBalancerName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
],
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"publicIPAddress": {
"id": "[variables('publicIPAddressID')]"
}
}
}
],
"backendAddressPools": [
{
"name": "[variables('bePoolName')]"
}
],
"inboundNatPools": [
{
"name": "[variables('natPoolName')]",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "Tcp",
"frontendPortRangeStart": "[variables('natStartPort')]",
"frontendPortRangeEnd": "[variables('natEndPort')]",
"backendPort": "[variables('natBackendPort')]"
}
}
],
"loadBalancingRules": [
{
"name": "LBRule",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"backendAddressPool": {
"id": "[variables('lbPoolID')]"
},
"protocol": "Tcp",
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"probe": {
"id": "[variables('lbProbeID')]"
}
}
}
],
"probes": [
{
"name": "tcpProbe",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachineScaleSets",
"apiVersion": "2020-06-01",
"name": "[variables('namingInfix')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('vmSku')]",
"tier": "Standard",
"capacity": "[parameters('instanceCount')]"
},
"dependsOn": [
"[resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
],
"properties": {
"overprovision": true,
"upgradePolicy": {
"mode": "Automatic"
},
"singlePlacementGroup": "[parameters('singlePlacementGroup')]",
"platformFaultDomainCount": "[parameters('platformFaultDomainCount')]",
"virtualMachineProfile": {
"storageProfile": {
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 128,
"lun": 0,
"createOption": "Empty"
}
],
"imageReference": "[variables('imageReference')]"
},
"osProfile": {
"computerNamePrefix": "[variables('namingInfix')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"networkProfile": {
"networkInterfaceConfigurations": [
{
"name": "[variables('nicName')]",
"properties": {
"primary": true,
"ipConfigurations": [
{
"name": "[variables('ipConfigName')]",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"loadBalancerBackendAddressPools": [
{
"id": "[variables('lbPoolID')]"
}
],
"loadBalancerInboundNatPools": [
{
"id": "[resourceId('Microsoft.Network/loadBalancers/inboundNatPools', variables('loadBalancerName'), variables('natPoolName'))]"
}
]
}
}
]
}
}
]
},
"extensionProfile": {
"extensions": [
{
"name": "customScript",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/prepare_vm_disks.ps1"
],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File prepare_vm_disks.ps1"
}
}
}
]
}
}
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2020-06-01",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Static",
"dnsSettings": {
"domainNameLabel": "[variables('longNamingInfix')]"
}
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-06-01",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
}
],
"outputs": {}
}
If you want to create multiple data disks with the copy function, you can add it like this
"storageProfile": {
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage"
},
"copy": [
{
"name": "dataDisks",
"count": "[parameters('numberOfDataDisks')]",
"input": {
"diskSizeGB": 1023,
"lun": "[copyIndex('dataDisks')]",
"createOption": "Empty"
}
}
],
After my validation, after the above deployment finishs, you need to initialize the disk in each instance, then you could get the expected result.
Reference: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/tutorial-use-disks-powershell#prepare-the-data-disks
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
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
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.