From 23ce7befe2435fd386e96ff1ff0b2e210ae85121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:12:06 +0200 Subject: [PATCH 01/12] add: attach p2s --- .../attach-vpn-gateway/README.md | 84 ++++++++ .../attach-vpn-gateway/attachVPNGateway.ps1 | 181 ++++++++++++++++++ .../attach-vpn-gateway/azuredeploy.json | 121 ++++++++++++ 3 files changed, 386 insertions(+) create mode 100644 samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md create mode 100644 samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 create mode 100644 samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json diff --git a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md new file mode 100644 index 00000000..1edae178 --- /dev/null +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md @@ -0,0 +1,84 @@ +# Attaches VPN gateway to Managed Instance virtual network + +### Contents + +[About this sample](#about-this-sample)
+[Before you begin](#before-you-begin)
+[Run this sample](#run-this-sample)
+[Sample details](#sample-details)
+[Disclaimers](#disclaimers)
+[Related links](#related-links)
+ + + + +## About this sample + +- **Applies to:** Azure SQL Database +- **Key features:** Managed Instance +- **Workload:** n/a +- **Programming Language:** PowerShell +- **Authors:** Srdan Bozovic +- **Update history:** n/a + + + +## Before you begin + +To run this sample, you need the following prerequisites. + +**Software prerequisites:** + +1. PowerShell 5.1 +2. Azure PowerShell 5.4.2 or higher + +**Azure prerequisites:** + +1. Permission to manage Azure virtual network + + + +## Run this sample + +Run the script below from Windows PowerShell + +```powershell + +$scriptUrlBase = 'https://raw.githubusercontent.com/Microsoft/sql-server-samples/master/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway' + +$parameters = @{ + subscriptionId = '' + resourceGroupName = '' + virtualNetworkName = '' + certificateNamePrefix = '' + } + +Invoke-Command -ScriptBlock ([Scriptblock]::Create((iwr ($scriptUrlBase+'/attachVPNGateway.ps1?t='+ [DateTime]::Now.Ticks)).Content)) -ArgumentList $parameters $scriptUrlBase + +``` + + + +## Sample details + +This sample shows how to attach VPN Gateway to Managed Instance virtual network using PowerShell + +This is done in three steps: +- Create and install certificates on client machine +- Calculate future VPN Gateway subnet IP range +- Deploy ARM template that will attach VPN Gateway to subnet + + + +## Disclaimers +The scripts and this guide are copyright Microsoft Corporations and are provided as samples. They are not part of any Azure service and are not covered by any SLA or other Azure-related agreements. They are provided as-is with no warranties express or implied. Microsoft takes no responsibility for the use of the scripts or the accuracy of this document. Familiarize yourself with the scripts before using them. + + + +## Related Links + + +For more information, see these articles: + +- [What is a Managed Instance (preview)?](https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance) +- [Configure a VNet for Azure SQL Database Managed Instance](https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance-vnet-configuration) \ No newline at end of file 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 new file mode 100644 index 00000000..86036df2 --- /dev/null +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/attachVPNGateway.ps1 @@ -0,0 +1,181 @@ +$parameters = $args[0] + +$subscriptionId = $parameters['subscriptionId'] +$resourceGroupName = $parameters['resourceGroupName'] +$virtualNetworkName = $parameters['virtualNetworkName'] +$certificateNamePrefix = $parameters['certificateNamePrefix'] +$force = $parameters['force'] + +$scriptUrlBase = $args[1] + +function Ensure-Login () +{ + $context = Get-AzureRmContext + If($context.Subscription -eq $null) + { + Write-Host "Loging in ..." + If((Login-AzureRmAccount -ErrorAction SilentlyContinue -ErrorVariable Errors) -eq $null) + { + Write-Host ("Login failed: {0}" -f $Errors[0].Exception.Message) -ForegroundColor Red + Break + } + } + Write-Host "User logedin." -ForegroundColor Green +} + +function Select-SubscriptionId { + param ( + $subscriptionId + ) + Write-Host "Selecting subscription '$subscriptionId'." + $context = Get-AzureRmContext + If($context.Subscription.Id -ne $subscriptionId) + { + Try + { + Select-AzureRmSubscription -SubscriptionId $subscriptionId -ErrorAction Stop | Out-null + } + Catch + { + Write-Host "Subscription selection failed: $_" -ForegroundColor Red + Break + } + } + Write-Host "Subscription selected." -ForegroundColor Green +} + +function Load-VirtualNetwork { + param ( + $resourceGroupName, + $virtualNetworkName + ) + Write-Host("Loading virtual network '{0}' in resource group '{1}'." -f $virtualNetworkName, $resourceGroupName) + $virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName -ErrorAction SilentlyContinue + If($virtualNetwork.Id -ne $null) + { + Write-Host "Virtual network loaded." -ForegroundColor Green + return $virtualNetwork + } + else + { + Write-Host "Virtual network not found." -ForegroundColor Red + Break + } +} + +function Load-ResourceGroup { + param ( + $resourceGroupName + ) + Write-Host("Loading resource group '{0}'." -f $resourceGroupName) + $resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName + If($resourceGroup.ResourceId -ne $null) + { + Write-Host "Resource group loaded." -ForegroundColor Green + return $resourceGroup + } + else + { + Write-Host "Resource group not found." -ForegroundColor Red + Break + } +} + +function ConvertCidrToUint32Array +{ + param($cidrRange) + $cidrRangeParts = $cidrRange.Split(@(".","/")) + $ipnum = ([Convert]::ToUInt32($cidrRangeParts[0]) -shl 24) -bor ` + ([Convert]::ToUInt32($cidrRangeParts[1]) -shl 16) -bor ` + ([Convert]::ToUInt32($cidrRangeParts[2]) -shl 8) -bor ` + [Convert]::ToUInt32($cidrRangeParts[3]) + + $maskbits = [System.Convert]::ToInt32($cidrRangeParts[4]) + $mask = 0xffffffff + $mask = $mask -shl (32 -$maskbits) + $ipstart = $ipnum -band $mask + $ipend = $ipnum -bor ($mask -bxor 0xffffffff) + return @($ipstart, $ipend) +} + +function ConvertUInt32ToIPAddress +{ + param($uint32IP) + $v1 = $uint32IP -band 0xff + $v2 = ($uint32IP -shr 8) -band 0xff + $v3 = ($uint32IP -shr 16) -band 0xff + $v4 = ($uint32IP -shr 24) + return "$v4.$v3.$v2.$v1" +} + +function CalculateNextAddressPrefix +{ + param($virtualNetwork, $prefixLength) + Write-Host "Calculating address prefix." + $startIPAddress = 0 + ForEach($addressPrefix in $virtualNetwork.AddressSpace.AddressPrefixes) + { + $endIPAddress = (ConvertCidrToUint32Array $addressPrefix)[1] + If($endIPAddress -gt $startIPAddress) + { + $startIPAddress = $endIPAddress + } + } + $startIPAddress += 1 + return (ConvertUInt32ToIPAddress $startIPAddress) + "/" + $prefixLength +} + +function CalculateVpnClientAddressPoolPrefix +{ + param($gatewaySubnetPrefix) + Write-Host "Calculating VPN client address pool prefix." + If($gatewaySubnetPrefix.StartsWith("10.")) + { + return "192.168.0.0/24" + } + else + { + return "172.16.0.0/24" + } + +} + +Ensure-Login +Select-SubscriptionId -subscriptionId $subscriptionId + +$virtualNetwork = Load-VirtualNetwork -resourceGroupName $resourceGroupName -virtualNetworkName $virtualNetworkName + +$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName + +$certificate = New-SelfSignedCertificate -Type Custom -KeySpec Signature ` + -Subject ("CN=$certificateNamePrefix"+"P2SRoot") -KeyExportPolicy Exportable ` + -HashAlgorithm sha256 -KeyLength 2048 ` + -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsageProperty Sign -KeyUsage CertSign + +$certificateThumbprint = $certificate.Thumbprint + +New-SelfSignedCertificate -Type Custom -DnsName ($certificateNamePrefix+"P2SChild") -KeySpec Signature ` + -Subject ("CN=$certificateNamePrefix"+"P2SChild") -KeyExportPolicy Exportable ` + -HashAlgorithm sha256 -KeyLength 2048 ` + -CertStoreLocation "Cert:\CurrentUser\My" ` + -Signer $certificate -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2") | Out-null + +$publicRootCertData = [Convert]::ToBase64String((Get-Item cert:\currentuser\my\$certificateThumbprint).RawData) + +$gatewaySubnetPrefix = CalculateNextAddressPrefix $virtualNetwork 28 + +$vpnClientAddressPoolPrefix = CalculateVpnClientAddressPoolPrefix $gatewaySubnetPrefix + +Write-Host + +# Start the deployment +Write-Host "Starting deployment..." + +$templateParameters = @{ + virtualNetworkName = $virtualNetworkName + gatewaySubnetPrefix = $gatewaySubnetPrefix + vpnClientAddressPoolPrefix = $vpnClientAddressPoolPrefix + publicRootCertData = $publicRootCertData + } + +New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json') -TemplateParameterObject $templateParameters 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 new file mode 100644 index 00000000..a97f558f --- /dev/null +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/azuredeploy.json @@ -0,0 +1,121 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.1", + "parameters": { + "virtualNetworkName": { + "type": "string", + "metadata": { + "description": "Enter virtual network name. If you leave this field blank name will be created by the template." + } + }, + "gatewaySubnetPrefix": { + "type": "string", + "metadata": { + "description": "The prefix for the GatewaySubnet where the VirtualNetworkGateway will be deployed. This must be at least /29." + } + }, + "vpnClientAddressPoolPrefix": { + "type": "string", + "metadata": { + "description": "The IP address range from which VPN clients will receive an IP address when connected. Range specified must not overlap with on-premise network." + } + }, + "publicRootCertData": { + "type": "string", + "metadata": { + "description": "Client root certificate data used to authenticate VPN clients." + } + } + }, + "variables": { + "gatewayPublicIpAddressName": "[concat('GatewayIP', substring(uniqueString(resourceGroup().id),0,3))]", + "gatewayName": "[concat('Gateway', substring(uniqueString(resourceGroup().id),0,3))]", + "gatewaySku": "Basic", + "gatewaySubnetName": "GatewaySubnet", + "clientRootCertName": "RootCert" + }, + "resources": [ + { + "name": "[parameters('virtualNetworkName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2018-02-01", + "dependsOn": [ + "[variables('routeTableName')]" + ], + "location": "[parameters('location')]", + "properties": { + "mode": "Incremental", + "addressSpace": { + "addressPrefixes": [ + "[parameters('gatewaySubnetPrefix')]" + ] + }, + "subnets": [ + { + "name": "[variables('gatewaySubnetName')]", + "properties": { + "addressPrefix": "[parameters('gatewaySubnetPrefix')]" + } + } + ] + } + }, + { + "apiVersion": "2017-10-01", + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('gatewayPublicIpAddressName')]", + "location": "[resourceGroup().location]", + "properties": { + "publicIPAllocationMethod": "Dynamic" + } + }, + { + "apiVersion": "2017-10-01", + "type": "Microsoft.Network/virtualNetworkGateways", + "name": "[variables('gatewayName')]", + "location": "[resourceGroup().location]", + "dependsOn": [ + "[concat('Microsoft.Network/publicIPAddresses/', variables('gatewayPublicIpAddressName'))]", + "[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]" + ], + "properties": { + "ipConfigurations": [ + { + "properties": { + "privateIPAllocationMethod": "Dynamic", + "subnet": { + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), variables('gatewaySubnetName'))]" + }, + "publicIPAddress": { + "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('gatewayPublicIpAddressName'))]" + } + }, + "name": "vnetGatewayConfig" + } + ], + "sku": { + "name": "[variables('gatewaySku')]", + "tier": "[variables('gatewaySku')]" + }, + "gatewayType": "Vpn", + "vpnType": "RouteBased", + "enableBgp": "false", + "vpnClientConfiguration": { + "vpnClientAddressPool": { + "addressPrefixes": [ + "[parameters('vpnClientAddressPoolPrefix')]" + ] + }, + "vpnClientRootCertificates": [ + { + "name": "[variables('clientRootCertName')]", + "properties": { + "PublicCertData": "[parameters('publicRootCertData')]" + } + } + ] + } + } + } + ] +} \ No newline at end of file From b71c7b532ba5ccf1ce0962b071984729cb8df3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:18:08 +0200 Subject: [PATCH 02/12] fix --- .../azure-sql-db-managed-instance/attach-vpn-gateway/README.md | 2 +- .../attach-vpn-gateway/attachVPNGateway.ps1 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md index 1edae178..e38acde9 100644 --- a/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md +++ b/samples/manage/azure-sql-db-managed-instance/attach-vpn-gateway/README.md @@ -53,7 +53,7 @@ $parameters = @{ certificateNamePrefix = '' } -Invoke-Command -ScriptBlock ([Scriptblock]::Create((iwr ($scriptUrlBase+'/attachVPNGateway.ps1?t='+ [DateTime]::Now.Ticks)).Content)) -ArgumentList $parameters $scriptUrlBase +Invoke-Command -ScriptBlock ([Scriptblock]::Create((iwr ($scriptUrlBase+'/attachVPNGateway.ps1?t='+ [DateTime]::Now.Ticks)).Content)) -ArgumentList $parameters, $scriptUrlBase ``` 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 86036df2..3d861da7 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 @@ -172,6 +172,7 @@ Write-Host Write-Host "Starting deployment..." $templateParameters = @{ + location = $virtualNetwork.Location virtualNetworkName = $virtualNetworkName gatewaySubnetPrefix = $gatewaySubnetPrefix vpnClientAddressPoolPrefix = $vpnClientAddressPoolPrefix From d8b92e6aeedb949b478f2899d6050f4898290b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:21:16 +0200 Subject: [PATCH 03/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 1 - .../attach-vpn-gateway/azuredeploy.json | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 3d861da7..86036df2 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 @@ -172,7 +172,6 @@ Write-Host Write-Host "Starting deployment..." $templateParameters = @{ - location = $virtualNetwork.Location virtualNetworkName = $virtualNetworkName gatewaySubnetPrefix = $gatewaySubnetPrefix vpnClientAddressPoolPrefix = $vpnClientAddressPoolPrefix 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 a97f558f..ed2c56fb 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 @@ -2,6 +2,13 @@ "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", "contentVersion": "1.0.0.1", "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "Enter location. If you leave this field blank resource group location would be used." + } + }, "virtualNetworkName": { "type": "string", "metadata": { From d079f586ea4d996d5345b8e34dea6c4b216e8b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:22:11 +0200 Subject: [PATCH 04/12] fix --- .../attach-vpn-gateway/azuredeploy.json | 3 --- 1 file changed, 3 deletions(-) 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 ed2c56fb..ad959edb 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 @@ -46,9 +46,6 @@ "name": "[parameters('virtualNetworkName')]", "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2018-02-01", - "dependsOn": [ - "[variables('routeTableName')]" - ], "location": "[parameters('location')]", "properties": { "mode": "Incremental", From cf583a6553cfaa7f4818730daacbd764796fb3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:26:47 +0200 Subject: [PATCH 05/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 86036df2..5863cc1d 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 @@ -178,4 +178,4 @@ $templateParameters = @{ publicRootCertData = $publicRootCertData } -New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json') -TemplateParameterObject $templateParameters +New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json'+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters From 3bb73cb0f67aecfe7572e2d4d501f32cba38d7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:27:38 +0200 Subject: [PATCH 06/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5863cc1d..8d4ba24d 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 @@ -178,4 +178,4 @@ $templateParameters = @{ publicRootCertData = $publicRootCertData } -New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json'+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters +New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters From 1375b202c3c5a0853e2a4def34d6f1bb403e608e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:33:16 +0200 Subject: [PATCH 07/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 2 +- .../attach-vpn-gateway/azuredeploy.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 8d4ba24d..cc24262a 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 @@ -178,4 +178,4 @@ $templateParameters = @{ publicRootCertData = $publicRootCertData } -New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters +New-AzureRmResourceGroupDeployment -Mode Incremental -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters 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 ad959edb..6a53bcec 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 @@ -48,7 +48,6 @@ "apiVersion": "2018-02-01", "location": "[parameters('location')]", "properties": { - "mode": "Incremental", "addressSpace": { "addressPrefixes": [ "[parameters('gatewaySubnetPrefix')]" From 1d366f2c00254a7b4cdbf1e7d7a9d1039f527e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:56:01 +0200 Subject: [PATCH 08/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 19 +++++++++++++++ .../attach-vpn-gateway/azuredeploy.json | 24 +------------------ 2 files changed, 20 insertions(+), 23 deletions(-) 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": [ From 30c2d596bc09209bcd0c141237e05cf310abbc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:57:56 +0200 Subject: [PATCH 09/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c0cd07bc..ae643f0e 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 @@ -197,4 +197,4 @@ $templateParameters = @{ publicRootCertData = $publicRootCertData } -New-AzureRmResourceGroupDeployment -Mode Incremental -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters +New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters From 5aa58c7c49a6bf340d7ba78a34579a95144e01fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 03:59:50 +0200 Subject: [PATCH 10/12] fix --- .../attach-vpn-gateway/attachVPNGateway.ps1 | 2 ++ 1 file changed, 2 insertions(+) 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 ae643f0e..176dc9df 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 @@ -185,6 +185,8 @@ $vpnClientAddressPoolPrefix = CalculateVpnClientAddressPoolPrefix $gatewaySubnet $virtualNetwork.AddressSpace.AddressPrefixes.Add($gatewaySubnetPrefix) Add-AzureRmVirtualNetworkSubnetConfig -Name GatewaySubnet -VirtualNetwork $virtualNetwork -AddressPrefix $gatewaySubnetPrefix | Out-Null +Set-VirtualNetwork $virtualNetwork + Write-Host # Start the deployment From b90627e0a01fa1525dc680b1418c37630478e211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 04:06:12 +0200 Subject: [PATCH 11/12] fix --- .../attach-vpn-gateway/azuredeploy.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7f357ff6..822a302c 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 @@ -35,8 +35,8 @@ } }, "variables": { - "gatewayPublicIpAddressName": "[concat('GatewayIP', substring(uniqueString(resourceGroup().id),0,3))]", - "gatewayName": "[concat('Gateway', substring(uniqueString(resourceGroup().id),0,3))]", + "gatewayPublicIpAddressName": "[concat('GatewayIP-', uniqueString(resourceGroup().id))]", + "gatewayName": "[concat('Gateway-', uniqueString(resourceGroup().id))]", "gatewaySku": "Basic", "gatewaySubnetName": "GatewaySubnet", "clientRootCertName": "RootCert" From 67950e163260055ff0b755199f5d070c71db95ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sr=C4=91an=20Bo=C5=BEovi=C4=87?= Date: Fri, 24 Aug 2018 08:56:32 +0200 Subject: [PATCH 12/12] add: placeholder for attach jumpbox --- .../attach-jumpbox/attachJumpbox.ps1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/manage/azure-sql-db-managed-instance/attach-jumpbox/attachJumpbox.ps1 diff --git a/samples/manage/azure-sql-db-managed-instance/attach-jumpbox/attachJumpbox.ps1 b/samples/manage/azure-sql-db-managed-instance/attach-jumpbox/attachJumpbox.ps1 new file mode 100644 index 00000000..fc6bb0ec --- /dev/null +++ b/samples/manage/azure-sql-db-managed-instance/attach-jumpbox/attachJumpbox.ps1 @@ -0,0 +1 @@ +#placeholder \ No newline at end of file