Without knowing what arguments you’re giving the parameters, I couldn’t say why you’re getting an err about the subnet not being valid but I would guess that you’re either not using proper CIDR notation or you provided a subnet address space that doesn’t jive with the vnet address space.
Here’s a valid template, from your example above. Notice I’ve changed the name
parameter to vnetname
. This is because New-AzResourceGroupDeployment
already has a required parameter called name
. You’ll trip it up when your template uses parameters with the same names as the cmdlet.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetname": {
"type": "string"
},
"location": {
"type": "string"
},
"addressPrefix": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"subnetAddressPrefix": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2018-08-01",
"name": "[parameters('vnetname')]",
"type": "Microsoft.Network/virtualNetworks",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetAddressPrefix')]"
}
}
]
}
}
]
}
Here’s the parameter template. Name
has been changed to vnetname
here as well. Take a look at how the address spaces are notated. This is CIDR notation and it’s what Azure requires.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetname": {
"value": "myVnet"
},
"location": {
"value": "WestUS"
},
"addressPrefix": {
"value": "10.10.0.0/16"
},
"subnetName": {
"value": "mySubnet"
},
"subnetAddressPrefix": {
"value": "10.10.1.0/24"
}
}
}
I removed the DDOS protection stuff for the sake of simplicity since that’s an entirely new subresource that needs to be built. Also removed the resource group parameters since a resource group deployment will specify this with the cmdlet; it’s not needed in the template.
You then deploy these together like so, New-AzResourceGroupDeployment -ResourceGroupName myresourcegroup -TemplateFile .\vnet.json -TemplateParameterFile .\vnet.parameters.json -Name mydeployment -Verbose
When learning ARM templates, start small and simple, get it working, and then build up in complexity.
You should also take a look at the vnet template reference docs, here.