Public/Deploy/IaaS/networking/managedNetwork/New-CmAzIaasNetworking.json

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "NetworkingArrayObject": {
            "type": "Array"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Resources/Deployments",
            "apiVersion": "2019-10-01",
            "name": "[concat('Cm_network_deployment_',copyIndex('NetworkingArrayObjectCopy'))]",
            "resourceGroup": "[parameters('NetworkingArrayObject')[copyIndex('NetworkingArrayObjectCopy')].resourceGroup.Name]",
            "copy": {
                "name": "NetworkingArrayObjectCopy",
                "count": "[length(parameters('NetworkingArrayObject'))]"
            },
            "properties": {
                "mode": "Incremental",
                "expressionEvaluationOptions": {
                    "scope": "Inner"
                },
                "parameters": {
                    "VnetArmObject": {
                        "value": "[parameters('NetworkingArrayObject')[copyIndex('NetworkingArrayObjectCopy')].vnets]"
                    },
                    "RouteTableArmObject": {
                        "value": "[parameters('NetworkingArrayObject')[copyIndex('NetworkingArrayObjectCopy')].routeTables]"
                    }
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "VnetArmObject": {
                            "type": "Array",
                            "metadata": {
                                "description": "vnet object with all required parameters"
                            }
                        },
                        "RouteTableArmObject": {
                            "type": "Array",
                            "metadata": {
                                "description": "route table object with all required parameters"
                            }
                        }
                    },
                    "resources": [
                        {
                            "condition": "[not(equals(parameters('VnetArmObject')[copyIndex('vnetCopy')].vnetName, 'none'))]",
                            "type": "Microsoft.Network/virtualNetworks",
                            "dependsOn": [
                                "routeTableCopy"
                            ],
                            "apiVersion": "2019-12-01",
                            "name": "[parameters('VnetArmObject')[copyIndex('vnetCopy')].vnetName]",
                            "location": "[if(not(empty(parameters('VnetArmObject')[copyIndex('vnetCopy')].location)), parameters('VnetArmObject')[copyIndex('vnetCopy')].location, resourceGroup().location)]",
                            "tags": {
                                "cm-service": "[parameters('VnetArmObject')[copyIndex('vnetCopy')]['service']['publish']['vnet']]"
                            },
                            "copy": {
                                "name": "vnetCopy",
                                "count": "[length(parameters('VnetArmObject'))]"
                            },
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": "[parameters('VnetArmObject')[copyIndex('vnetCopy')].addressSpace]"
                                },
                                "dhcpOptions": "[if(not(empty(parameters('VnetArmObject')[copyIndex('vnetCopy')].dnsServers)), json(concat('{\"dnsServers\": [', replace(replace(string(parameters('VnetArmObject')[copyIndex('vnetCopy')].dnsServers), '[', ''), ']', ''), ']}')), json('null'))]",
                                "copy": [
                                    {
                                        "name": "subnets",
                                        "count": "[length( parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets)]",
                                        "input": {
                                            "name": "[parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].subnetName]",
                                            "properties": {
                                                "addressPrefix": "[parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].cidr]",
                                                "serviceEndpoints": "[parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].serviceEndpoints]",
                                                "networkSecurityGroup": "[if(not(empty(parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].networkSecurityGroup)), json(concat('{\"id\": \"', resourceId('Microsoft.Network/networkSecurityGroups', parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].networkSecurityGroup), '\"}')), json('null'))]",
                                                "routeTable": "[if(not(empty(parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].routeTable)), json(concat('{\"id\": \"', resourceId('Microsoft.Network/routeTables', parameters('VnetArmObject')[copyIndex('vnetCopy')].subnets[copyIndex('subnets')].routeTable), '\"}')), json('null'))]",
                                                "privateEndpointNetworkPolicies": "Disabled"
                                            }
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "condition": "[not(equals(parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].tableName, 'none'))]",
                            "name": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].tableName]",
                            "type": "Microsoft.Network/routeTables",
                            "apiVersion": "2019-12-01",
                            "location": "[if(not(empty(parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].location)), parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].location, resourceGroup().location)]",
                            "tags": {
                                "cm-service": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')]['service']['publish']['routeTable']]"
                            },
                            "copy": {
                                "name": "routeTableCopy",
                                "count": "[length( parameters('RouteTableArmObject'))]"
                            },
                            "properties": {
                                "disableBgpRoutePropagation": "[not(parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routePropagation)]",
                                "copy": [
                                    {
                                        "name": "routes",
                                        "count": "[length(parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routes)]",
                                        "input": {
                                            "name": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routes[copyIndex('routes')].routeName]",
                                            "properties": {
                                                "addressPrefix": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routes[copyIndex('routes')].cidr]",
                                                "nextHopType": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routes[copyIndex('routes')].nextHopType]",
                                                "nextHopIpAddress": "[parameters('RouteTableArmObject')[copyIndex('routeTableCopy')].routes[copyIndex('routes')].nextHopIpAddress]"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}