Microsoft Azure Terraform Module v1.0

terraform-azure-hub-spoke-network

Executive Summary

Enterprise-grade Terraform module for deploying a hub-and-spoke network topology on Azure. Provisions a centralized hub virtual network with Azure Firewall (Standard/Premium), Azure Bastion, VPN Gateway, ExpressRoute Gateway, and Route Server, alongside configurable spoke VNets with automatic peering and firewall-routed UDRs. Includes integrated diagnostic settings for comprehensive network monitoring.

Overview

14

Resources

VNets, Peerings, Firewall, Bastion, Gateways, Route Tables, Diagnostics

18

Variables

Configurable input parameters

17

Outputs

IDs, IPs, DNS names for all components

3

Examples

Basic, Advanced, Complete

Architecture Diagram

On-Premises Network
VPN Gateway / ExpressRoute
|
Hub Virtual Network
Azure Firewall
Premium + IDPS + DNS Proxy
Azure Bastion
Standard SKU
Route Server
↓ Peering
↓ Peering
↓ Peering
Spoke: App
Frontend Subnet
Backend Subnet
Spoke: Data
DB Subnet
Storage Subnet
Spoke: DMZ
Public Subnet
Private Subnet
UDR: 0.0.0.0/0 → Azure Firewall

Component Breakdown

ResourcePurposeOptional
azurerm_virtual_network.hubHub VNet with reserved subnets (Firewall, Gateway, Bastion, RouteServer)No
azurerm_virtual_network.spokeSpoke VNets with configurable subnetsNo
azurerm_virtual_network_peeringBidirectional hub-to-spoke peering with gateway transitNo
azurerm_firewallAzure Firewall (Standard/Premium) with policy and rule collectionsYes
azurerm_firewall_policyFirewall policy with IDPS, DNS proxy, threat intelligenceYes
azurerm_bastion_hostAzure Bastion for secure VM access (Basic/Standard)Yes
azurerm_virtual_network_gateway.vpnVPN Gateway for site-to-site connectivityYes
azurerm_virtual_network_gateway.expressrouteExpressRoute Gateway for private connectivityYes
azurerm_route_serverRoute Server for dynamic NVA route exchangeYes
azurerm_route_table.spokeUDR tables routing spoke traffic through firewallYes
azurerm_monitor_diagnostic_settingFirewall and Bastion diagnostic logs to Log AnalyticsYes

Data Flow

Spoke Workload
UDR (0.0.0.0/0)
Azure Firewall
Internet / On-Prem

Spoke-to-Internet: Traffic from spoke subnets with route_through_firewall = true hits the UDR default route, forcing all egress through Azure Firewall for inspection. Spoke-to-Spoke: Inter-spoke traffic transits the hub via peering and firewall. On-Premises: VPN/ExpressRoute terminates at the hub gateway; spokes use remote gateways via peering config.

Security Controls

Network Segmentation

- Hub-spoke isolation with VNet peering
- Per-spoke UDR forcing traffic through firewall
- BGP route propagation disabled on spoke route tables
- Subnet-level security boundaries

Firewall & Threat Protection

- Azure Firewall Premium with IDPS (Alert mode)
- Threat intelligence mode: Deny
- DNS proxy for FQDN-based rules
- Network, application, and NAT rule collections
- Diagnostic logging for all rule hits

Access Control

- Azure Bastion for secure SSH/RDP (no public IPs on VMs)
- Standard SKU with advanced features
- Audit logging for Bastion sessions

Hybrid Connectivity

- VPN Gateway with RouteBased VPN
- ExpressRoute for private WAN
- Gateway transit enabled for spoke access
- Route Server for NVA BGP integration

Industry Adaptation

Enterprise IT

Hub-spoke with shared services, centralized firewall, and multi-spoke isolation for different business units

Financial Services

ExpressRoute for dedicated connectivity, Firewall Premium with IDPS, strict UDR enforcement on all spokes

Healthcare

Network segmentation for HIPAA compliance, Bastion for audit-logged access, no public IP exposure

Government

Azure Firewall threat intelligence in Deny mode, full diagnostic logging, Route Server for NVA integration

Production Readiness Checklist

Configuration Reference

Key Variables

VariableTypeDefaultDescription
name_prefixstring--Prefix for all resource names
resource_group_namestring--Resource group name
locationstring--Azure region
hub_vnet_address_spacelist(string)--Hub VNet CIDR blocks
spoke_vnetsmap(object){}Spoke VNets with subnets and firewall routing
enable_firewallbooltrueDeploy Azure Firewall
firewall_sku_tierstringPremiumStandard or Premium
enable_bastionbooltrueDeploy Azure Bastion
enable_vpn_gatewayboolfalseDeploy VPN Gateway
enable_expressrouteboolfalseDeploy ExpressRoute Gateway
enable_route_serverboolfalseDeploy Azure Route Server

Deployment

terraform init
terraform plan -var-file="networking.tfvars"
terraform apply -var-file="networking.tfvars"

# Verify hub VNet
az network vnet show --name myproject-hub-vnet --resource-group rg-networking
# Check firewall status
az network firewall show --name myproject-fw --resource-group rg-networking

Links

Hub-Spoke Reference Architecture | Azure Firewall Docs | Basic Example | Advanced Example | Complete Example