How do I configure an Azure Virtual Network VPN gateway?
The following is an example of how to configure an Azure Virtual Network VPN gateway. This includes the virtual network, the subnet for the gateway, the public IP address, and the VPN gateway itself. Each resource is interconnected to create the VPN setup.
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
// Create a resource group
const example = new azure.core.ResourceGroup("example", {
name: "example-resources",
location: "West Europe",
});
// Create a virtual network
const exampleVirtualNetwork = new azure.network.VirtualNetwork("example", {
name: "example-vnet",
addressSpaces: ["10.0.0.0/16"],
location: example.location,
resourceGroupName: example.name,
});
// Create a subnet for the VPN gateway
const gateway = new azure.network.Subnet("gateway", {
name: "GatewaySubnet",
resourceGroupName: example.name,
virtualNetworkName: exampleVirtualNetwork.name,
addressPrefixes: ["10.0.1.0/24"],
});
// Create a public IP address for the gateway
const examplePublicIp = new azure.network.PublicIp("example", {
name: "example-pip",
location: example.location,
resourceGroupName: example.name,
allocationMethod: "Dynamic",
sku: "Basic",
});
// Create the VPN gateway
const exampleVirtualNetworkGateway = new azure.network.VirtualNetworkGateway("example", {
name: "example-gateway",
location: example.location,
resourceGroupName: example.name,
type: "Vpn",
vpnType: "RouteBased",
activeActive: false,
enableBgp: false,
sku: "Basic",
ipConfigurations: [{
name: "vnetGatewayConfig",
publicIpAddressId: examplePublicIp.id,
privateIpAddressAllocation: "Dynamic",
subnetId: gateway.id,
}],
});
export const resourceGroupName = example.name;
export const virtualNetworkName = exampleVirtualNetwork.name;
export const subnetName = gateway.name;
export const publicIpAddress = examplePublicIp.ipAddress;
export const vpnGatewayId = exampleVirtualNetworkGateway.id;
This code sets up an Azure resource group, a virtual network, and a subnet specifically for the VPN gateway. It then creates a dynamic public IP address, which is used by the VPN gateway. Finally, the code outputs the names and IDs of the created resources so you can easily reference them.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.