New-AzResourceGroupDeployment fails when deploying a virtual network via ARM template. It seems like the ARM template is iterating through one single IP adress by seeing it's dots ('.') as delimiter:
Errormessage:
New-AzResourceGroupDeployment : 16:00:26 - The deployment 'vm2' failed with error(s). Showing 1 out of 1 error(s).
Status Message: Cannot parse the request. (Code: InvalidRequestFormat)
- Unexpected character encountered while parsing value: {. Path 'properties.addressSpace.addressPrefixes', line 1, position 133. (Code:InvalidJson)
- After parsing a value an unexpected character was encountered: :. Path 'properties.addressSpace.addressPrefixes[0]', line 1, position 145. (Code:InvalidJson)
- After parsing a value an unexpected character was encountered: :. Path 'properties.addressSpace.addressPrefixes[0]', line 1, position 145. (Code:InvalidJson)
- After parsing a value an unexpected character was encountered: :. Path 'properties.addressSpace.addressPrefixes[0]', line 1, position 145. (Code:InvalidJson)
- After parsing a value an unexpected character was encountered: :. Path 'properties.addressSpace.addressPrefixes[0]', line 1, position 145. (Code:InvalidJson)
CorrelationId: 5cf0698f-1f96-4adf-a242-312ded6bc9fe
At line:1 char:1
New-AzResourceGroupDeployment -ResourceGroupName "clientname-rg-vm-01 ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [New-AzResourceGroupDeployment], Exception
FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
The part of the template file looks like this:
..."parameters": {
"addressPrefixes": {
"type": "array"
},
"subnets": {
"type": "array"
}
},...
..."properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": "[parameters('subnets')]"
},...
The full template file looks like this:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"metadata": {
"description": "Omgeving Dev, Tst, Acc, Prd"
}
},
"companyName": {
"type": "string"
},
"resourceType": {
"type": "string"
},
"sequenceNumber": {
"type": "string"
},
"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"
},
"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": {
"vmName": "[concat(parameters('companyName'), parameters('resourceType'), parameters('sequenceNumber'), parameters('environment'))]",
"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": "[variables('vmName')]",
"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": "[variables('vmName')]",
"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')]"
}
}
}
The part of the ARM parameter file looks like this:
..."addressPrefixes": {
"value": [
"172.50.28.0/22"
]
},
"subnets": {
"value": [
{
"name": "default_VM01",
"properties": {
"addressPrefix": "172.50.28.0/26"
}
}
]
},...
Deployed using New-AzResourceGroupDeployment as well :-
PowerShell version:-
NOTE:- When using az deployment group create
need to use cli(az login) and when using New-new-Azresourcegroupdeployment
(Connect-AzAccount)
For more information please refer this MICROSOFT DOCUMENTATION| Create Virtual Machine using Template.