Microsoft Azure Documentation

Create a Site-to-Site VPN Gateway using Azure Resource Manager (ARM) templates and PowerShell

This article guides you through the process of creating a Site-to-Site (S2S) VPN gateway in Azure using Azure Resource Manager (ARM) templates and PowerShell. This setup allows you to securely connect your on-premises network to your Azure virtual network.

Note: This article focuses on using ARM templates for declarative deployment. For imperative deployment using PowerShell cmdlets, refer to Create a VNet-to-VNet connection.

Prerequisites

Step 1: Download the ARM Template and Parameters File

We'll use pre-defined ARM templates for simplicity. Download the following two files:

Save these files to a local directory on your computer.

Step 2: Modify the Parameters File

Open azuredeploy.parameters.json in a text editor. You'll need to modify the following parameters to match your environment:

Example modification:

"virtualNetworkName": {
    "value": "MyAzureVNet"
},
"virtualNetworkAddressPrefixes": {
    "value": "10.1.0.0/16"
},
"gatewaySubnetPrefix": {
    "value": "10.1.255.0/27"
},
"gatewaySku": {
    "value": "VpnGw1"
},
"vpnGatewayName": {
    "value": "MyVpnGateway"
},
"location": {
    "value": "eastus"
},
"localNetworkGatewayName": {
    "value": "MyOnPremNetwork"
},
"localNetworkGatewayAddressPrefixes": {
    "value": "192.168.1.0/24"
},
"sharedKey": {
    "value": "MySuperSecretSharedKey123!"
}

Step 3: Deploy the ARM Template using PowerShell

Open PowerShell and navigate to the directory where you saved the ARM template files. Run the following command to deploy the resources:

Login-AzAccount

$resourceGroupName = "MyResourceGroup" # Replace with your desired resource group name
New-AzResourceGroup -Name $resourceGroupName -Location eastus # Replace 'eastus' with your chosen location

New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateFile ./azuredeploy.json `
    -TemplateParameterFile ./azuredeploy.parameters.json

This command will:

The deployment process can take a significant amount of time (15-30 minutes or more) as Azure provisions the VPN gateway.

Step 4: Verify the Deployment

Once the deployment is complete, you can verify the resources in the Azure portal or by using PowerShell commands:

Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName
Get-AzVpnGateway -ResourceGroupName $resourceGroupName
Get-AzPublicIpAddress -ResourceGroupName $resourceGroupName
Get-AzLocalNetworkGateway -ResourceGroupName $resourceGroupName
Get-AzVpnConnection -ResourceGroupName $resourceGroupName

Tip: After the VPN gateway is created, you will need to configure your on-premises VPN device with the public IP address of the Azure VPN gateway and the pre-shared key to establish the connection.

Step 5: Configure On-Premises VPN Device

This step is highly dependent on your specific on-premises VPN device. Generally, you will need to configure the following:

  1. Remote Gateway IP Address: The public IP address of the Azure VPN Gateway. You can find this in the Azure portal or using Get-AzPublicIpAddress.
  2. Shared Secret (Pre-Shared Key): The value you specified in the sharedKey parameter.
  3. IKE Version: Ensure it matches the configuration of your Azure VPN Gateway (typically IKEv2).
  4. IPsec/IKE Parameters: Configure encryption, integrity, Diffie-Hellman groups, and lifetimes to match Azure's defaults or your specific requirements.
  5. Traffic Selectors: Configure the traffic selectors to allow traffic between your on-premises network address space and your Azure Virtual Network address space.

Troubleshooting

Warning: Incorrectly configured VPN devices can lead to connectivity issues and potential security vulnerabilities. Always refer to your VPN device manufacturer's documentation.

By following these steps, you can successfully deploy a Site-to-Site VPN gateway in Azure using ARM templates and PowerShell, establishing a secure connection to your on-premises network.