1
votes

I am trying to create NIC card for VM through Azure ARM template. But my script also creates concats NIC to app gateway. But as of now I am only creating VM and NIC. Is there a condition to skip the Concatenation of App gateway and NIC. Below is the NIC creation template:

{
    "comments": "NIC_Creation",
    "tags": {
        "owner": "[parameters('owner')]"
    },
    "condition": "[equals(parameters('CreateVM'), 'yes')]",
    "dependsOn": [
        // "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]",
        // "[resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]",
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name'))]",
        "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('NSG_Name'))]",
        "[resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name'))]"

    ],
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[parameters('NIC_Name')]",
    "apiVersion": "2018-02-01",
    "location": "[parameters('myvmlocation')]",
    "scale": null,
    "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "e319fe3b-4162-4501-81e7-b657be52f411",
        "ipConfigurations": [
            {
                "name": "ipconfig1",
                "etag": "W/\"a9185125-7a6e-4811-ae29-4afe520e7c4f\"",
                "properties": {
                    "provisioningState": "Succeeded",
                    "privateIPAddress": "192.168.1.4",//192.168.1.4   //172.19.0.5
                    "privateIPAllocationMethod": "Dynamic",
                    "publicIPAddress": {
                        "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]"
                    },
                    "subnet": {
                        "id": "[concat(resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name')), '/subnets/',parameters('subnetname'))]"
                    },
                    "primary": true,
                    "privateIPAddressVersion": "IPv4",
                     "applicationGatewayBackendAddressPools": [

                        {
                            "condition": "[equals(parameters('CreateAppgateway'), 'yes')]",
                            "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/sxBackendPool')]"
                        },
                        {
                            "condition": "[equals(parameters('CreateAppgateway'), 'yes')]",
                            "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/nxBackendPool')]"
                        }
                    ]
                }
            }
        ],
        "dnsSettings": {
            "dnsServers": [],
            "appliedDnsServers": []
        },
        "macAddress": "00-0D-3A-1F-51-61",
        "enableAcceleratedNetworking": false,
        "enableIPForwarding": false,
        "networkSecurityGroup": {
            "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('NSG_Name'))]"
        },
        "primary": true
    }
},

I have added a condition inside applicationGatewayBackendAddressPools but it is not working. Can any one help me here please.

2

2 Answers

1
votes

No, you cannot put conditions on individual properties. what you could do is use if() function together with variables and json() function to calculate desired result

"applicationGatewayBackendAddressPools": "[if(equals(parameters('CreateAppgateway'), 'yes'), variables('applicationGateways'), json('null'))]"
0
votes

First of all, all the credits goes to https://stackoverflow.com/users/6067741/4c74356b41 (4c74356b41) who helped to solve this. Thanks for your help.

I used the IF function and implemented as shown below . It worked!!

"variables": {
    "AssociateNIC":  
    [{
        "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/sxBackendPool')]"
    },
    {
        "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/nxBackendPool')]"
    }]

},

"applicationGatewayBackendAddressPools": "[if(equals(parameters('CreateAppgateway'), 'yes'), variables('AssociateNIC'), json('null'))]"