Azure ARM Template for VM with Conditions for Private / Public IP and VM Count

Dennis Birk 401 Reputation points
2020-04-24T06:34:10.797+00:00

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?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,418 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dennis Birk 401 Reputation points
    2020-05-05T13:16:15.567+00:00

    I found the solution:

    publicIPAddress": {
    "id": "[if(variables('requirePublicIP'), resourceId('Microsoft.Network/publicIPAddresses',Concat(variables('virtualMachineName'),copyIndex(0),'-pip')),json('null'))]"
    }

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dennis Birk 401 Reputation points
    2020-05-04T06:57:41.497+00:00

    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...

    0 comments No comments