diff --git a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 index cc24262a..c0cd07bc 100644 --- a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 @@ -81,6 +81,22 @@ function Load-ResourceGroup { } } +function Set-VirtualNetwork +{ + param($virtualNetwork) + + Write-Host "Applying changes to the virtual network." + Try + { + Set-AzureRmVirtualNetwork -VirtualNetwork $virtualNetwork -ErrorAction Stop | Out-Null + } + Catch + { + Write-Host "Failed: $_" -ForegroundColor Red + } + +} + function ConvertCidrToUint32Array { param($cidrRange) @@ -166,6 +182,9 @@ $gatewaySubnetPrefix = CalculateNextAddressPrefix $virtualNetwork 28 $vpnClientAddressPoolPrefix = CalculateVpnClientAddressPoolPrefix $gatewaySubnetPrefix +$virtualNetwork.AddressSpace.AddressPrefixes.Add($gatewaySubnetPrefix) +Add-AzureRmVirtualNetworkSubnetConfig -Name GatewaySubnet -VirtualNetwork $virtualNetwork -AddressPrefix $gatewaySubnetPrefix | Out-Null + Write-Host # Start the deployment diff --git a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json index 6a53bcec..7f357ff6 100644 --- a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json @@ -42,27 +42,6 @@ "clientRootCertName": "RootCert" }, "resources": [ - { - "name": "[parameters('virtualNetworkName')]", - "type": "Microsoft.Network/virtualNetworks", - "apiVersion": "2018-02-01", - "location": "[parameters('location')]", - "properties": { - "addressSpace": { - "addressPrefixes": [ - "[parameters('gatewaySubnetPrefix')]" - ] - }, - "subnets": [ - { - "name": "[variables('gatewaySubnetName')]", - "properties": { - "addressPrefix": "[parameters('gatewaySubnetPrefix')]" - } - } - ] - } - }, { "apiVersion": "2017-10-01", "type": "Microsoft.Network/publicIPAddresses", @@ -78,8 +57,7 @@ "name": "[variables('gatewayName')]", "location": "[resourceGroup().location]", "dependsOn": [ - "[concat('Microsoft.Network/publicIPAddresses/', variables('gatewayPublicIpAddressName'))]", - "[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]" + "[concat('Microsoft.Network/publicIPAddresses/', variables('gatewayPublicIpAddressName'))]" ], "properties": { "ipConfigurations": [