I tried with the above code but not able to get it right. And also, I can see that it is asking for the old rules. I am trying to update the new rules while not disturbing the old rules.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"lbName": {
"type": "string"
},
"lbLocation": {
"type": "string"
},
"vnetId": {
"type": "string"
},
"subnetId": {
"type": "string"
},
"healthProbes": {
"type": "array",
"defaultValue": [
{
"name": "HealthProbe-TCP-80",
"protocol": "TCP",
"port": "80",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": null
},
{
"name": "HealthProbe-TCP-443",
"protocol": "TCP",
"port": "443",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": null
},
{
"name": "HealthProbe-HTTP-443",
"protocol": "HTTP",
"port": "443",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": "TestPath"
}
]
}
},
"variables": {
"virtualNetworkName": "[parameters('vnetId')]",
"subnetName": "[Parameters('subnetId')]",
"frontEndIPConfigName": "LoadBalancerFrontEnd",
"feId": "[concat(parameters('lbName'),'/frontendIPConfigurations/loadBalancerFrontend')]",
"backendPoolConfigName": "qwertyBEPool",
"beId": "[concat(parameters('lbName'), '/backendAddressPools/qwertyBEPool')]",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"resources": [
{
"apiVersion": "2019-06-01",
"name": "[parameters('lbName')]",
"type": "Microsoft.Network/loadBalancers",
"location": "[parameters('lbLocation')]",
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
],
"backendAddressPools": [
{
"name": "LoadBalancerBackend"
}
],
"copy": [
{
"name": "probes",
"count": "[length(parameters('healthProbes'))]",
"input": {
"name": "[parameters('healthProbes')[copyIndex('probes')].name]",
"properties": {
"protocol": "[parameters('healthProbes')[copyIndex('probes')].protocol]",
"port": "[parameters('healthProbes')[copyIndex('probes')].port]",
"intervalInSeconds": "[parameters('healthProbes')[copyIndex('probes')].intervalInSeconds]",
"numberOfProbes": "[parameters('healthProbes')[copyIndex('probes')].numberOfProbes]",
"requestPath": "[parameters('healthProbes')[copyIndex('probes')].requestPath]"
}
}
}
]
}
}
]
}
To update a resource in an Azure Resource Manager template, you need to specify the updated resource in a second template that's either linked or included as a subtemplate using the Microsoft.Resources/deployments
resource type.
First, you must reference the resource once in the template to create it and then reference the resource by the same name to update it later. However, if two resources have the same name in a template, Resource Manager throws an exception. To avoid this error, specify the updated resource in a second template that's either linked or included as a subtemplate using the Microsoft.Resources/deployments resource type.
Second, you must either specify the name of the existing property to change or a new name for a property to add in the nested template. You must also specify the original properties and their original values. If you fail to provide the original properties and values, Resource Manager assumes you want to create a new resource and deletes the original resource.
For example, if you have created resources from this 201-2-vms-loadbalancer-lbrules template, you just need to download the existing template from Load balancer----Settings---Export template. Then add the new loadBalancingRules and probes, edit the template to meet your requirements, then redeploy the edited full template with this command
New-AzResourceGroupDeployment -ResourceGroupName yourRG -mode Incremental -TemplateFile ".\template.json" -TemplateParameterFile ".\parameters.json"
For example,
"loadBalancingRules": [
{
"name": "LBRule",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"protocol": "Tcp",
"enableTcpReset": false,
"loadDistribution": "Default",
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/backendAddressPools/BackendPool1')]"
},
"probe": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/probes/tcpProbe')]"
}
}
},
{
"name": "LBRule-new",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": 8080,
"backendPort": 8080,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"protocol": "Tcp",
"enableTcpReset": false,
"loadDistribution": "Default",
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/backendAddressPools/BackendPool1')]"
},
"probe": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/probes/tcpProbe')]"
}
}
}
],
"probes": [
{
"name": "tcpProbe",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
},
{
"name": "tcpProbe-new",
"properties": {
"protocol": "Tcp",
"port": 8080,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
],
....