Azure / Azure/azure-quickstart-templates

Error deploying VMs to existing vnet json

Open
#1,174 31 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Bicep
Stars
14.9k
Forks
16.2k
Avg merge
6d 21h
Merged PRs (30d)
6

Description

Hi guys, I'm trying to build a custom built .json script with 2 VM's, 2 Nics, a storage account, Availability set & a public IP to connect to an **existing** vnet but I keep getting a tonne of errors, I've tried different functions and parameters and still nothing works :(

This is the error I get

`New-AzureRmResourceGroupDeployment : InvalidTemplate: Deployment template
validation failed: 'The template variable 'vnetID' is not valid: Unable to
evaluate template language function 'resourceId': function requires exactly
one multi-segmented argument which must be resource type including resource
provider namespace. Current function arguments 'Microsoft.Network/virtualNetworks,/subscriptions/subscriptionid/resourceGroups/Test-ResGrp/providers/Microsoft.Network/virtualNetworks/TestCoreVnet'. Please see
http://aka.ms/arm-template-expressions/#resourceid for usage details..'.`

Here is my template

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "West Europe",
"allowedValues": [
"West US",
"East US",
"West Europe"
],
"metadata": {
"description": "Location of resources"
}
},
"newStorageAccountName": {
"type": "string",
"metadata": {
"description": "Name of new storage account"
}
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS"
],
"metadata": {
"description": "Type of storage account"
}
},
"publicIPName": {
"type": "string",
"metadata": {
"description": "Name of Public IP"
}
},
"publicIPAddressType": {
"type": "string",
"defaultValue": "Dynamic",
"allowedValues": [
"Dynamic"
],
"metadata": {
"description": "Type of Public Address"
}
},
"vmName": {
"type": "string",
"metadata": {
"description": "Name of the VM"
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"Standard_A2",
"Standard_A3",
"Standard_A4"
],
"metadata": {
"description": "Size of the VM"
}
},
"imagePublisher": {
"type": "string",
"defaultValue": "MicrosoftWindowsServer",
"metadata": {
"description": "Image Publisher"
}
},
"imageOffer": {
"type": "string",
"defaultValue": "WindowsServer",
"metadata": {
"description": "Image Offer"
}
},
"imageSKU": {
"type": "string",
"defaultValue": "2012-R2-Datacenter",
"metadata": {
"description": "Image SKU"
}
},
"adminUserName": {
"type": "string",
"metadata": {
"description": "VM Admin Username"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "VM Password"
}
},
"existingVNETName": {
"type": "string",
"metadata": {
"description": "VNET Name"
}
},
"newSubnetName": {
"type": "string",
"metadata": {
"description": "Name of the subnet to add"
}
},
"newSubnetAddressPrefix": {
"type": "string",
"defaultValue": "10.0.0.0/24",
"metadata": {
"description": "Address space of the subnet to add"
}
},
"nicName": {
"type": "string",
"metadata": {
"description": "Network Interface Name"
}
}
},
"variables": {
"availabilitySetName": "TestAvailSet",
"storageAccountType": "Standard_LRS",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('existingVNETName'))]",
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/', parameters('newSubnetName'))]",
"numberOfInstances": 2
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[parameters('newStorageAccountName')]",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Compute/availabilitySets",
"name": "[variables('availabilitySetName')]",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('location')]",
"properties": { }
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[parameters('publicIPName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "[parameters('publicIPAddressType')]"
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(parameters('nicName'), copyindex())]",
"location": "[parameters('location')]",
"copy": {
"name": "nicLoop",
"count": "[variables('numberOfInstances')]"
},
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('existingVNETName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPName'))]"
},
"subnet": {
"id": "[variables('subnet1Ref')]"
}
}
}
]
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat(parameters('vmName'), copyindex())]",
"copy": {
"name": "virtualMachineLoop",
"count": "[variables('numberOfInstances')]"
},
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'), copyindex())]",
"[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]"
],
"properties": {
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets',variables('availabilitySetName'))]"
},
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat(parameters('vmName'), copyIndex())]",
"adminUsername": "[parameters('adminUserName')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[parameters('imagePublisher')]",
"offer": "[parameters('imageOffer')]",
"sku": "[parameters('imageSKU')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/vhds/','osdisk', copyindex(), '.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('nicName'),copyindex()))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net')]"
}
}
}
}
]
}

Any help would be greatly appreciated

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the pasted deployment template and the New-AzureRmResourceGroupDeployment entry point, tracing the vnetID and subnet1Ref variables and the network interface dependencies. Validate the template against an existing VNet and confirm that the intended two VMs, NICs, storage account, availability set, and public IP deploy successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.