Azure Resource Manager Template Functions
- To give additional functionality to ARM template as we are working on json format
- All the functions are documented here
Excercise
- To use copyIndex along with Copy to create 3 subnets
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion" : "1.0.0.0",
"parameters": {
"vnetaddresspace": {
"type": "array",
"defaultValue":["192.168.0.0/16"]
},
"count": {
"type" : "int",
"defaultValue" : 3
}
},
"resources":[
{
"name": "fromarm",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-04-01",
"location": "Central US",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('vnetaddresspace')]"
}
}
},
{
"name": "subnet1",
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2019-04-01",
"properties": {
"addressPrefix": "192.168.0.0/24"
},
"dependsOn": ["fromarm"],
"copy": {
"name": "websitescopy",
"count": "[parameters('count')]"
}
}
]
}
- This needs to be corrected.
- Correct this using the following template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion" : "1.0.0.0",
"parameters": {
"vnetaddresspace": {
"type": "array",
"defaultValue":["192.168.0.0/16"]
},
"count": {
"type" : "int",
"defaultValue" : 3
},
"subnetnames":{
"type": "array",
"defaultValue": ["web", "business","data"]
},
"subnetAddress":{
"type": "array",
"defaultValue": ["192.168.0.0/24","192.168.1.0/24", "192.168.2.0/24"]
}
},
"resources":[
{
"name": "fromarm",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2019-04-01",
"location": "Central US",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('vnetaddresspace')]"
}
}
},
{
"name": "<Replace this with parametres & Copy Index>",
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2019-04-01",
"properties": {
"addressPrefix": "<Replace this with parametres & Copy Index>"
},
"dependsOn": ["fromarm"],
"copy": {
"name": "websitescopy",
"count": "[parameters('count')]"
}
}
]
}
- In the subnet resource use parameters. Use copyIndex function to get the current iteration.