I found the solution:
publicIPAddress": {
"id": "[if(variables('requirePublicIP'), resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName'),copyIndex(0),'-pip')),json('null'))]"
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello, I created a new ARM Template with conditions as parameter for private and public IP and VM count.
I can use a template with conditions for private and public IP, but not with VM count (copy) or I can use a template with VM count, but not with conditions.
In variable section I use the following code from GitHub https://github.com/Azure/azure-quickstart-templates/blob/master/201-vm-new-or-existing-conditions/azuredeploy.json for condition, for public or private IP:
"requirePublicIP":"[and(equals(parameters('NetworkInterfaceType'),'Public'),greater(parameters('PIPCount'),0))]",
"publicIP1": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName')))]"
}
In resource section by networkInterfaces I use the follwing code from GitHub:
"publicIPAddress": "[if(variables('requirePublicIP'),variables('publicIP1'),json('null'))]"
Thats working fine, but I can't use no VM count (copy).
If I use VM count (copy) then use this code from GitHub https://github.com/Azure/azure-quickstart-templates/blob/master/201-vm-copy-index-loops/azuredeploy.json:
"publicIPAddress":{
"id": "[resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName'),copyIndex(0),'-pip'))]"
}
Thats working fine, but I can't use the condition for public and privat IP.
How can I combine the conditions for public and private IP and VM count?
I found the solution:
publicIPAddress": {
"id": "[if(variables('requirePublicIP'), resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName'),copyIndex(0),'-pip')),json('null'))]"
}
I need a possibility to generate the ID for the puplic IP with a condition for public or private IP:
"publicIPAddress": "[if(variables('requirePublicIP'),variables('publicIP1'),json('null'))]"
"publicIPAddress":{
"id": "[resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName'),copyIndex(0),'-pip'))]"
}
So I need a mix of both...