Public/IaaS/vpngw/New-CmAzIaasVpnGw.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "defaultValue": "[resourceGroup().location]",
            "type": "String",
            "metadata": {
                "description": "location"
            }
        },
        "VpnGwObject": {
            "type": "Object",
            "metadata": {
                "description": "vpn object to with all required parameters"
            }
        }
    },
    "variables": {
    },
    "resources": [
        {
            "type": "Microsoft.Resources/Deployments",
            "apiVersion": "2019-10-01",
            "name": "[concat(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayName, '-', copyIndex('vpnGatewayCopy'), '-', uniqueString(resourceGroup().id))]",
            "copy": {
                "name": "vpnGatewayCopy",
                "count": "[length(parameters('VpnGwObject').VpnGw)]"
            },
            "properties": {
                "mode": "Incremental",
                "expressionEvaluationOptions": {
                    "scope": "outer"
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                    },
                    "resources": [
                        {
                            "condition": "[not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewaySubnetPrefix))]",
                            "type": "Microsoft.Network/virtualNetworks/subnets",
                            "apiVersion": "2019-04-01",
                            "name": "[concat(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].virtualNetworkName, '/', 'GatewaySubnet')]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "addressPrefix": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewaySubnetPrefix]"
                            }
                        },
                        {
                            "apiVersion": "2019-04-01",
                            "type": "Microsoft.Network/publicIPAddresses",
                            "name": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayPublicIPName]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "publicIPAllocationMethod": "Dynamic"
                            }
                        },
                        {
                            "apiVersion": "2019-04-01",
                            "type": "Microsoft.Network/virtualNetworkGateways",
                            "name": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayName]",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[concat('Microsoft.Network/publicIPAddresses/', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayPublicIPName)]"
                            ],
                            "properties": {
                                "ipConfigurations": [
                                    {
                                        "properties": {
                                            "privateIPAllocationMethod": "Dynamic",
                                            "subnet": {
                                                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].virtualNetworkName, 'GatewaySubnet')]"
                                            },
                                            "publicIPAddress": {
                                                "id": "[resourceId('Microsoft.Network/publicIPAddresses',parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayPublicIPName)]"
                                            }
                                        },
                                        "name": "vnetGatewayConfig"
                                    }
                                ],
                                "sku": {
                                    "name": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].Sku]",
                                    "tier": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].Sku]"
                                },
                                "gatewayType": "Vpn",
                                "vpnType": "RouteBased",
                                "enableBgp": false,
                                "vpnClientConfiguration": {
                                    "vpnClientAddressPool": {
                                        "addressPrefixes": [
                                            "[if(and(not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.VpnAddressPool)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.RootCertificateName)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.clientRootCertData))), parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.VpnAddressPool, json('null'))]"
                                        ]
                                    },
                                    "vpnClientRootCertificates": [
                                        {
                                            "name": "[if(and(not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.VpnAddressPool)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.RootCertificateName)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.clientRootCertData))), parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.RootCertificateName, json('null'))]",
                                            "properties": {
                                                "publicCertData": "[if(and(not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.VpnAddressPool)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.RootCertificateName)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.clientRootCertData))), parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].P2s.clientRootCertData, json('null'))]"
                                            }
                                        }
                                    ]
                                }
                            }
                        },
                        {
                            "apiVersion": "2019-04-01",
                            "condition": "[and(not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.cidrBlocks)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.clientSitePublicIP)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.SharedKey[0])))]",
                            "type": "Microsoft.Network/localNetworkGateways",
                            "name": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.localGatewayName]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "localNetworkAddressSpace": {
                                    "addressPrefixes": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.cidrBlocks]"
                                },
                                "gatewayIpAddress": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.clientSitePublicIP]"
                            }
                        },
                        {
                            "apiVersion": "2019-04-01",
                            "condition": "[and(not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.cidrBlocks)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.clientSitePublicIP)),not(empty(parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.SharedKey[0])))]",
                            "name": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.localGatewayName]",
                            "type": "Microsoft.Network/connections",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[resourceId('Microsoft.Network/virtualNetworkGateways', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayName)]",
                                "[resourceId('Microsoft.Network/localNetworkGateways', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.localGatewayName)]"
                            ],
                            "properties": {
                                "virtualNetworkGateway1": {
                                    "id": "[resourceId('Microsoft.Network/virtualNetworkGateways', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayName)]"
                                },
                                "localNetworkGateway2": {
                                    "id": "[resourceId('Microsoft.Network/localNetworkGateways', concat('localGateway', parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].GatewayName))]"
                                },
                                "connectionType": "IPsec",
                                "routingWeight": 10,
                                "sharedKey": "[parameters('VpnGwObject').VpnGw[copyIndex('vpnGatewayCopy')].S2s.SharedKey[0]]"
                            }
                        }
                    ]
                }
            }
        }
    ],
    "outputs": {
 
    }
}