Skip to content

About

Azure Virtual Network Terraform module — parameterised, azurerm 4.x, CI-validated · AIRCLOUD

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AIRCLOUD: DevOps, cloud and AI engineering

azure-virtual-network-module

Azure Virtual Network Terraform module — parameterised, azurerm 4.x, CI-validated.

CI License: MIT Release

Enterprise-grade Azure Virtual Network module with comprehensive networking and security features.

Features

✅ Multi-Address Space - Support for multiple CIDR blocks
✅ Advanced Subnets - Delegations, service endpoints, private endpoints
✅ Security Groups - NSGs with granular security rules
✅ Route Tables - Custom routing with BGP integration
✅ DDoS Protection - Azure DDoS Protection Standard
✅ Encryption - VNet encryption support
✅ DNS Configuration - Custom DNS servers
✅ Azure Policy - Compliance and security enforcement

Usage

Pin the module to a release tag:

module "virtual_network" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-network-module.git?ref=v1.0.0"

  # required inputs
  address_space       = []
  environment         = "..."
  location            = "..."
  resource_group_name = "..."
}

All inputs and outputs are listed in the generated reference below (Inputs, Outputs). Worked examples live in examples/.

Basic Example

module "virtual_network" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-network-module.git?ref=v1.0.0"

  name                = "vnet-prod-westeurope-001"
  location            = "westeurope"
  resource_group_name = "rg-production"
  environment         = "prod"
  address_space       = ["10.0.0.0/16"]

  subnets = {
    "default" = {
      address_prefixes = ["10.0.1.0/24"]
    }
  }

  tags = {
    Environment = "Production"
  }
}

Complete Example with Security

module "virtual_network" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-virtual-network-module.git?ref=v1.0.0"

  name                = "vnet-prod-westeurope-001"
  location            = "westeurope"
  resource_group_name = "rg-production"
  environment         = "prod"
  address_space       = ["10.0.0.0/16", "10.1.0.0/16"]

  # DNS Configuration
  dns_servers = ["168.63.129.16", "8.8.8.8"]

  # DDoS Protection
  enable_ddos_protection = true
  ddos_protection_plan_id = azurerm_network_ddos_protection_plan.main.id

  # Encryption
  encryption_enforcement = "AllowUnencrypted"

  subnets = {
    "web" = {
      address_prefixes = ["10.0.1.0/24"]
      service_endpoints = ["Microsoft.Storage", "Microsoft.Sql"]
      network_security_group_keys = ["web-nsg"]
      route_table_keys = ["web-rt"]
    }

    "app" = {
      address_prefixes = ["10.0.2.0/24"]
      network_security_group_keys = ["app-nsg"]
      route_table_keys = ["app-rt"]
    }

    "db" = {
      address_prefixes = ["10.0.3.0/24"]
      network_security_group_keys = ["db-nsg"]
      delegations = [
        {
          name = "sql-delegation"
          service_name = "Microsoft.Sql/managedInstances"
          actions = [
            "Microsoft.Network/virtualNetworks/subnets/join/action",
            "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
            "Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"
          ]
        }
      ]
    }

    "aks" = {
      address_prefixes = ["10.0.4.0/24"]
      delegations = [
        {
          name = "aks-delegation"
          service_name = "Microsoft.ContainerService/managedClusters"
          actions = [
            "Microsoft.Network/virtualNetworks/subnets/join/action"
          ]
        }
      ]
    }
  }

  network_security_groups = {
    "web-nsg" = {
      security_rules = [
        {
          name                       = "AllowHTTP"
          priority                   = 100
          direction                  = "Inbound"
          access                     = "Allow"
          protocol                   = "Tcp"
          source_port_range          = "*"
          destination_port_range     = "80"
          source_address_prefix      = "*"
          destination_address_prefix = "*"
        },
        {
          name                       = "AllowHTTPS"
          priority                   = 110
          direction                  = "Inbound"
          access                     = "Allow"
          protocol                   = "Tcp"
          source_port_range          = "*"
          destination_port_range     = "443"
          source_address_prefix      = "*"
          destination_address_prefix = "*"
        }
      ]
    }

    "app-nsg" = {
      security_rules = [
        {
          name                       = "AllowFromWeb"
          priority                   = 100
          direction                  = "Inbound"
          access                     = "Allow"
          protocol                   = "Tcp"
          source_port_range          = "*"
          destination_port_range     = "8080"
          source_address_prefix      = "10.0.1.0/24"
          destination_address_prefix = "*"
        }
      ]
    }

    "db-nsg" = {
      security_rules = [
        {
          name                       = "AllowFromApp"
          priority                   = 100
          direction                  = "Inbound"
          access                     = "Allow"
          protocol                   = "Tcp"
          source_port_range          = "*"
          destination_port_range     = "1433"
          source_address_prefix      = "10.0.2.0/24"
          destination_address_prefix = "*"
        }
      ]
    }
  }

  route_tables = {
    "web-rt" = {
      routes = [
        {
          name           = "ToInternet"
          address_prefix = "0.0.0.0/0"
          next_hop_type  = "Internet"
        }
      ]
    }

    "app-rt" = {
      disable_bgp_route_propagation = true
      routes = [
        {
          name                   = "ToFirewall"
          address_prefix         = "0.0.0.0/0"
          next_hop_type          = "VirtualAppliance"
          next_hop_in_ip_address = "10.0.100.4"
        }
      ]
    }
  }

  tags = {
    Environment = "Production"
    Security    = "High"
    Compliance  = "SOX"
  }
}

Examples

  • Basic - Simple VNet with one subnet
  • Complete - Full enterprise networking setup
  • Hub-Spoke - Hub and spoke topology

Security Features

Network Security

  • NSG Rules - Granular inbound/outbound filtering
  • Service Endpoints - Secure service access without public IPs
  • Private Endpoints - Private connectivity to Azure services
  • Route Tables - Custom routing and traffic control

Compliance & Governance

  • Azure Policy - Automated compliance enforcement
  • DDoS Protection - Advanced DDoS mitigation
  • Network Encryption - VNet traffic encryption
  • Delegation Support - Service-specific subnet delegation

Monitoring & Management

  • Network Watcher - Network monitoring and diagnostics
  • Flow Logs - NSG flow logging
  • Traffic Analytics - Network traffic insights

Version

Current version: v1.0.0

License

MIT

Reference

Requirements

Name Version
terraform >= 1.5.0
azurerm ~> 4.0

Providers

Name Version
azurerm 4.81.0

Modules

No modules.

Resources

Name Type
azurerm_management_lock.vnet_lock resource
azurerm_monitor_diagnostic_setting.vnet_diagnostics resource
azurerm_nat_gateway.nat_gateways resource
azurerm_nat_gateway_public_ip_association.nat_pip_associations resource
azurerm_network_ddos_protection_plan.main resource
azurerm_network_security_group.nsgs resource
azurerm_network_watcher.main resource
azurerm_network_watcher_flow_log.flow_logs resource
azurerm_public_ip.nat_pips resource
azurerm_resource_group.main resource
azurerm_resource_group_policy_assignment.no_rdp_from_internet resource
azurerm_resource_group_policy_assignment.no_ssh_from_internet resource
azurerm_resource_group_policy_assignment.nsg_on_subnets resource
azurerm_route_table.route_tables resource
azurerm_subnet.subnets resource
azurerm_subnet_network_security_group_association.nsg_associations resource
azurerm_subnet_route_table_association.rt_associations resource
azurerm_virtual_network.main resource
azurerm_resource_group.main data source

Inputs

Name Description Type Default Required
address_space Address space for the Virtual Network list(string) n/a yes
create_resource_group Create resource group if it doesn't exist bool false no
ddos_protection_plan_id ID of DDoS Protection Plan string null no
diagnostic_settings Diagnostic settings configuration
object({
logs = list(object({
category = string
}))
metrics = list(object({
category = string
enabled = bool
}))
})
{
"logs": [
{
"category": "VMProtectionAlerts"
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true
}
]
}
no
dns_servers List of DNS servers list(string) null no
enable_ddos_protection Enable DDoS Protection bool false no
enable_diagnostic_settings Enable diagnostic settings for Virtual Network bool true no
enable_network_watcher Enable Network Watcher for the region bool false no
enable_policy_assignments Enable Azure Policy assignments for this Virtual Network bool true no
enable_resource_lock Enable resource lock for Virtual Network bool false no
encryption_enforcement Encryption enforcement setting string "Unencrypted" no
environment Environment name (e.g., prod, dev, test) string n/a yes
flow_logs_storage_account_id Storage Account ID for Flow Logs string null no
location Azure region where resources will be created string n/a yes
lock_level Resource lock level: CanNotDelete or ReadOnly string "CanNotDelete" no
log_analytics_workspace_id Log Analytics Workspace ID for diagnostics and traffic analytics string null no
log_analytics_workspace_resource_id Log Analytics Workspace Resource ID for traffic analytics string null no
name Name of the Virtual Network. If null, will be auto-generated. string null no
naming_prefix Prefix for Virtual Network naming string "vnet" no
nat_gateways Map of NAT Gateways to create
map(object({
sku_name = optional(string, "Standard")
idle_timeout_in_minutes = optional(number, 4)
zones = optional(list(string), [])
public_ip = optional(object({
allocation_method = optional(string, "Static")
sku = optional(string, "Standard")
zones = optional(list(string), [])
}))
}))
{} no
network_security_groups Map of Network Security Groups to create
map(object({
security_rules = optional(list(object({
name = string
priority = number
direction = string
access = string
protocol = string
source_port_range = optional(string)
source_port_ranges = optional(list(string))
destination_port_range = optional(string)
destination_port_ranges = optional(list(string))
source_address_prefix = optional(string)
source_address_prefixes = optional(list(string))
destination_address_prefix = optional(string)
destination_address_prefixes = optional(list(string))
source_application_security_group_ids = optional(list(string))
destination_application_security_group_ids = optional(list(string))
})), [])
}))
{} no
resource_group_name Name of the resource group string n/a yes
route_tables Map of Route Tables to create
map(object({
disable_bgp_route_propagation = optional(bool, false)
routes = optional(list(object({
name = string
address_prefix = string
next_hop_type = string
next_hop_in_ip_address = optional(string)
})), [])
}))
{} no
subnets Map of subnets to create
map(object({
address_prefixes = list(string)
service_endpoints = optional(list(string), [])

delegations = optional(list(object({
name = string
service_name = string
actions = optional(list(string), [])
})), [])

private_endpoint_network_policies_enabled = optional(bool, true)
private_link_service_network_policies_enabled = optional(bool, true)

network_security_group_keys = optional(list(string), [])
route_table_keys = optional(list(string), [])

# Flow logs configuration
enable_flow_logs = optional(bool, false)
flow_logs_retention_days = optional(number, 30)
enable_traffic_analytics = optional(bool, false)
traffic_analytics_interval = optional(number, 60)
}))
{} no
tags Tags to apply to all resources map(string) {} no

Outputs

Name Description
address_space Virtual Network address space
id Virtual Network resource ID
name Virtual Network name
network_security_group_ids Map of NSG names to IDs
route_table_ids Map of Route Table names to IDs
subnet_address_prefixes Map of subnet names to address prefixes
subnet_ids Map of subnet names to IDs
vnet_guid Virtual Network GUID

Part of the AIRCLOUD Azure module catalog

Browse all modules with usage snippets in the module catalog or on github.com/AIRCLOUD-PL. Built and maintained by AIRCLOUD: DevOps, cloud and AI engineering. Need a hand with Azure landing zones or platform engineering? See aircloud.com.pl/consulting.

About

Azure Virtual Network Terraform module — parameterised, azurerm 4.x, CI-validated · AIRCLOUD

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages