1+ # main.tf
2+ # This file contains the main configuration for creating an Azure VPN Gateway and its supporting resources.
3+
4+ # Resource Group
5+ resource "azurerm_resource_group" "vpngw" {
6+ name = var. resource_group_name
7+ location = var. location
8+ }
9+
10+ # Virtual Network for VPN Gateway
11+ resource "azurerm_virtual_network" "vpngw" {
12+ name = " vpngw-vnet"
13+ address_space = [" 10.10.0.0/16" ]
14+ location = azurerm_resource_group. vpngw . location
15+ resource_group_name = azurerm_resource_group. vpngw . name
16+ }
17+
18+ # GatewaySubnet (required name and at least /27)
19+ resource "azurerm_subnet" "gateway" {
20+ name = " GatewaySubnet"
21+ resource_group_name = azurerm_resource_group. vpngw . name
22+ virtual_network_name = azurerm_virtual_network. vpngw . name
23+ address_prefixes = [" 10.10.1.0/27" ]
24+ }
25+
26+ # Public IP for VPN Gateway
27+ resource "azurerm_public_ip" "vpngw" {
28+ name = var. public_ip_name
29+ location = azurerm_resource_group. vpngw . location
30+ resource_group_name = azurerm_resource_group. vpngw . name
31+ allocation_method = " Static" # <-- Must be Static for Standard SKU
32+ sku = " Standard"
33+ }
34+
35+ # VPN Gateway
36+ resource "azurerm_virtual_network_gateway" "vpngw" {
37+ name = var. vpn_gateway_name
38+ location = azurerm_resource_group. vpngw . location
39+ resource_group_name = azurerm_resource_group. vpngw . name
40+ type = " Vpn"
41+ vpn_type = " RouteBased"
42+ active_active = false
43+ enable_bgp = false
44+ sku = var. vpn_gateway_sku
45+
46+ ip_configuration {
47+ name = " vnetGatewayConfig"
48+ public_ip_address_id = azurerm_public_ip. vpngw . id
49+ subnet_id = azurerm_subnet. gateway . id
50+ private_ip_address_allocation = " Dynamic"
51+ }
52+ }
0 commit comments