From 6260eea866c972550a3fd601d73dfa4aa8d11063 Mon Sep 17 00:00:00 2001 From: Yair Raviv Date: Sun, 7 Jul 2024 18:25:38 +0300 Subject: [PATCH] Updated existing vnet nested tempalte --- .../marketplace-single/mainTemplate.json | 18 +++++ .../nestedtemplates/vnet-existing.json | 74 ++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/azure/templates/marketplace-single/mainTemplate.json b/azure/templates/marketplace-single/mainTemplate.json index 9acc1ccf..39d6d22b 100644 --- a/azure/templates/marketplace-single/mainTemplate.json +++ b/azure/templates/marketplace-single/mainTemplate.json @@ -607,6 +607,24 @@ "virtualNetworkExistingRGName": { "value": "[variables('vnetRGName')]" }, + "Subnet1Name": { + "value": "[parameters('Subnet1Name')]" + }, + "Subnet1Prefix": { + "value": "[parameters('Subnet1Prefix')]" + }, + "Subnet1StartAddress": { + "value": "[parameters('Subnet1StartAddress')]" + }, + "Subnet2Name": { + "value": "[parameters('Subnet2Name')]" + }, + "Subnet2Prefix": { + "value": "[parameters('Subnet2Prefix')]" + }, + "Subnet2StartAddress": { + "value": "[parameters('Subnet2StartAddress')]" + }, "tagsByResource": { "value": "[parameters('tagsByResource')]" }, diff --git a/azure/templates/nestedtemplates/vnet-existing.json b/azure/templates/nestedtemplates/vnet-existing.json index 415f5361..54e6e60d 100644 --- a/azure/templates/nestedtemplates/vnet-existing.json +++ b/azure/templates/nestedtemplates/vnet-existing.json @@ -5,7 +5,7 @@ "location": { "type": "string" }, - "virtualNetworkName": { + "virtualNetworkName": { "type": "string", "metadata": { "description": "The name of the virtual network" @@ -27,6 +27,46 @@ "type": "string", "defaultValue": "default-nsg" }, + "Subnet1Name": { + "type": "string", + "metadata": { + "description": "The name of the 1st subnet" + }, + "defaultValue": "Frontend" + }, + "Subnet1Prefix": { + "type": "string", + "metadata": { + "description": "The address prefix of the 1st subnet" + }, + "defaultValue": "10.0.1.0/24" + }, + "Subnet1StartAddress": { + "type": "string", + "metadata": { + "description": "The first avaialable address on the 1st subnet" + } + }, + "Subnet2Name": { + "type": "string", + "metadata": { + "description": "The name of the 2nd subnet" + }, + "defaultValue": "Backend" + }, + "Subnet2Prefix": { + "type": "string", + "metadata": { + "description": "The address prefix of the 2nd subnet" + }, + "defaultValue": "10.0.2.0/24" + }, + "Subnet2StartAddress": { + "type": "string", + "metadata": { + "description": "The first avaialable address on the 2nd subnet" + } + }, "tagsByResource": { "type": "object", "defaultValue": {} @@ -36,6 +76,38 @@ "vnetId": "[resourceId(parameters('virtualNetworkExistingRGName'),'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]" }, "resources": [ + { + "type": "Microsoft.ResourceGraph/queries", + "apiVersion": "2018-09-01-preview", + "name": "subnet1query", + "location": "[parameters('location')]", + "etag": "test", + "properties": { + "description": "check_if_subnet1_exists", + "query": "resources | where type == \"microsoft.network/virtualnetworks\"| where resourceGroup == \"[parameteres('virtualNetworkExistingRGName')]\"| where name == \"[parameteres('virtualNetworkName')]\"" + } + }, + { + "type": "Microsoft.Network/routeTables", + "dependsOn": ["resourceId('Microsoft.ResourceGraph/queries', 'subnet1query')"], + "condition": ["contains(resources('subnet1query').result[0].properties.subnets, parameters('Subnet1Name'))"], + "apiVersion": "2020-06-01", + "location": "[parameters('location')]", + "name": "[parameters('subnet1Name')]", + "properties": { + "routes": [ + { + "name": "To-Internet", + "properties": { + "addressPrefix": "0.0.0.0/0", + "nextHopType": "VirtualAppliance", + "nextHopIpAddress": "[parameters('subnet1StartAddress')]" + } + } + ] + }, + "tags": "[ if(contains(parameters('tagsByResource'), 'Microsoft.Network/routeTables'), parameters('tagsByResource')['Microsoft.Network/routeTables'], json('{}')) ]" + }, { "type": "Microsoft.Network/networkSecurityGroups", "condition": "[parameters('deployNsg')]",