Pratztr
Pratztr

Reputation: 57

Error: Code="NetcfgSubnetRangesOverlap"; Subnet is not valid because its IP address range overlaps with that of an existing subnet in virtual network

I am provisioning a sqlmi instance in azure, and we have 2 subnets created. Primary subnet and secondary subnet(DR). The secondary subnet fails to get created with below error. The records are created also in phpipam. Although the record is added in the ipma but subnet creation failed.

Error: Subnet Name: "sub1"): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="NetcfgSubnetRangesOverlap" Message="Subnet 'sub1' is not valid because its IP address range overlaps with that of an existing subnet in virtual network 'vnet1'." Details=[]
    
    │   with module.secondarysubnet[0].azurerm_subnet.subnet,
    │   on .terraform/modules/secondarysubnet/main.tf line 23, in resource "azurerm_subnet" "subnet":
    │   23: resource "azurerm_subnet" "subnet" {

Address space: 100.90.69.64/26

How to check the overlap on the subnets/vnets as I am new to networking.

Upvotes: 0

Views: 126

Answers (1)

Vinay B
Vinay B

Reputation: 2401

Subnet is not valid because its IP address range overlaps with that of an existing subnet in virtual network while using terraform

To compare the address prefix (CIDR) of the subnets in the same Vnet follow the steps below

In general, 100.90.69.64/26 has an IP range from 100.90.69.64 to 100.90.69.127 so make sure no subnet overlapping range.

you can list subnets and their addresses prefixes in the Vnet with the command

az network vnet subnet list --resource-group <resource-group> --vnet-name vnet1 --query "[].{Name:name, AddressPrefix:addressPrefix}" -o table

Here instead of IP addressing I used the private range 10.0.0.0/16 instead of the carrier-grade NAT range (100.64.0.0/10) and also I removed the vnet_address_space variable since we're using a fixed private range

Sample Configuration:

resource "azurerm_virtual_network" "vnet" {
  name                = var.vnet_name
  resource_group_name = azurerm_resource_group.rg.name
  location           = azurerm_resource_group.rg.location
  address_space      = ["10.0.0.0/16"]  # Using proper private IP range
}


resource "azurerm_subnet" "primary" {
  name                 = var.primary_subnet_name
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.0.0/26"]  # Range: 10.0.0.0 - 10.0.0.63

  delegation {
    name = "managedinstancedelegation"
    service_delegation {
      name    = "Microsoft.Sql/managedInstances"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", 
                 "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action", 
                 "Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"]
    }
  }
}


resource "azurerm_subnet" "secondary" {
  name                 = var.secondary_subnet_name
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.0.64/26"]  # Range: 10.0.0.64 - 10.0.0.127

  delegation {
    name = "managedinstancedelegation"
    service_delegation {
      name    = "Microsoft.Sql/managedInstances"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", 
                 "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action", 
                 "Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action"]
    }
  }
}

Deployment

refer:

Virtual network warns about address overlap with itself

https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/instance-create-terraform?view=azuresql

Upvotes: 0

Related Questions