If you’re working within a big enterprise, chances are you’ll be handed a broad regional range by the network lead. Let’s say you get 10.32.0.0/11 for the whole of a region.
Now, each VNet needs a clean, isolated slice. Instead of allocating these ranges one at a time by hand, try this:
variable "region_cidr" { default = "10.32.0.0/11" }
variable "vnet_index" { default = 2 } # Choose third VNet for this example
locals {
vnet_cidr = cidrsubnet(var.region_cidr, 5, var.vnet_index) # /16 per VNet
}
resource "azurerm_virtual_network" "main" {
name = "vnet-${var.vnet_index}"
address_space = [local.vnet_cidr]
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
}
No copy-paste errors—just a variable and you’ve got unique, sequential VNet blocks ready for any region.